Re: [PHP] $GLOBALS example script on php.net

2011-03-07 Thread Ashim Kapoor
Before...");
print_r($globals);
foreach (array(
'GLOBALS',
'_ENV',
'HTTP_ENV_VARS',
'_POST',
'HTTP_POST_VARS',
'_GET',
'HTTP_GET_VARS',
'_COOKIE',
'HTTP_COOKIE_VARS',
'_SERVER',
'HTTP_SERVER_VARS',
'_FILES',
'HTTP_POST_FILES',
'_REQUEST'
) as $var) {
unset($globals[$var]);
}
print("After...");
   print_r($globals);

return $globals;
}

globals();
?>

array(7) { ["GLOBALS"]=> array(7) { ["GLOBALS"]=> *RECURSION* ["_POST"]=>
array(0) { } ["_GET"]=> array(0) { } ["_COOKIE"]=> array(0) { } ["_FILES"]=>
array(0) { } ["globalvar1"]=> int(1) ["globalvar2"]=> int(2) } ["_POST"]=>
array(0) { } ["_GET"]=> array(0) { } ["_COOKIE"]=> array(0) { } ["_FILES"]=>
array(0) { } ["globalvar1"]=> int(1) ["globalvar2"]=> int(2) }
Before...Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET]
=> Array ( ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) [globalvar1] => 1
[globalvar2] => 2 )
After...Array ( [globalvar1] => 1 [globalvar2] => 2 )

Ok I see it now.

Thank you all,
Ashim.


Re: [PHP] $GLOBALS example script on php.net

2011-03-06 Thread Ashim Kapoor
Unsetting doesn't leave user defined variables. Unsetting simply destroys
> variables (or removes elements from an array, etc). There is nothing magic
> or hidden in that script. I think the note meant exactly what it said: after
> creating a local copy of the $GLOBALS array and removing super globals from
> it, all that's left in it are user defined variables. And that's exactly
> what gets returned from the function.



This is a script vars.php

After...");
   print_r($globals);

return $globals;
}

globals();
?>

I called http://localhost/vars.php?a=1

I get : -

Before...Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET]
=> Array ( [a] => 1 ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) )
After...Array ( )

ALL the variables are UNSET. I have a user defined $_GET[a] but that goes
away too.

One second, what do you mean by user defined variables? Maybe I am lost in
comprehension


Re: [PHP] $GLOBALS example script on php.net

2011-03-06 Thread Ashim Kapoor
It doesn't though, it creates a copy of the $_GLOBALS super global array,
removes entries that will have been set by the system (i.e. it leaves
user-defined variables) and then returns the ones that are left, so in that,
the user note is perfectly correct.

What has me puzzled is how unsetting LEAVES user defined variables ? Why
would that happen ?

The array in the function lists the common server-defined variables
> (HTTP_VARS, etc), which it unsets from the local copy of the super global
> array ($globals). Basically, it loops through the un-named array, and unsets
> that index from $globals.
>

Thank you,
Ashim


Re: [PHP] $$var

2011-03-06 Thread Ashim Kapoor
> Hi Ashim,
>
> These are called Variable Variables. Ideally they should be avoided,
> as they introduce unnecessary legibility issues.
>
> This is what it does in a nutshell, it's actually quite simple:
>
> $foo = 'bar';
> $bar = 'foobar';
> echo $$foo;//This prints foobar
>
> What it does is, take the value of $foo (which is 'bar') and if a
> variable exists by that name, it will go forth and print the value of
> $bar; In this case foobar.
>

Alright Russel, Thank you,
Ashim.


[PHP] $$var

2011-03-06 Thread Ashim Kapoor
Dear All,

I was reading the php manual for session_register, and I found the following
line there : -


$_SESSION[$var] = $$var;

Why do I need $$ there ? Can someone explain?

Thank you,
Ashim


Re: [PHP] $GLOBALS example script on php.net

2011-03-05 Thread Ashim Kapoor
Dear Ashley,

I do follow the part when it creates a local copy of $GLOBALS.

When it unsets them, is there a subtlety of unset that it ONLY unsets system
defined entries? Could you please explain this ?

Thank you,
Ashim


Re: [PHP] $GLOBALS example script on php.net

2011-03-05 Thread Ashim Kapoor
>
> I'll remove it.
>

 How does one remove user notes from  php.net ?

Thank you,
Ashim


[PHP] $GLOBALS example script on php.net

2011-03-04 Thread Ashim Kapoor
Dear all,

I was reading this page
http://php.net/manual/en/reserved.variables.globals.php and  I found the
following script there : 


Here's a function which returns an array of all user defined global
variables:



I think that this script UNSETS each supergobal variable,but page says that
it returns ALL user defined vars ? Can some one tell me how that is ?

Thank you,
Ashim


Fwd: [PHP] Help needed with mysql import

2011-03-02 Thread Ashim Kapoor
-- Forwarded message --
From: Ashim Kapoor 
Date: Thu, Mar 3, 2011 at 7:22 AM
Subject: Re: [PHP] Help needed with mysql import
To: Jim Lucas 



CREATE TABLE IF NOT EXISTS `ajax_products` (
>  `id` int(11) NOT NULL auto_increment,
>  `name` varchar(64) NOT NULL default '',
>  `version` tinytext NOT NULL,
>  PRIMARY KEY  (`id`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
>
> It doesn't show a default value, but rather a default starting point for
> the
> AUTO_INCREMENT
>
> OP: Show us an export of your db table structure.
>
> Dear Jim,
 I read this in a book.  I dont have the table to show you.

Thank you,
Ashim


[PHP] Help needed with mysql import

2011-03-01 Thread Ashim Kapoor
Dear all,

I am trying to make a website with php and I found the following code in a
book and I am trying to import it. The following are the beginning of the
file i am trying to import with the command

mysql -u root -pmypassword certainty < dump

I get the following error : ERROR 1067 (42000) at line 9: Invalid default
value for 'id'

but when I see line 9 i see the value '0' for id which seems ok to me, I
also tried removing the quotes but same error.

Can someone guide me ?

Thank you,
Ashim

# MySQL dump 7.1
#
# Host: [host deleted] Database: certainty
#
# Server version 3.22.32
#
# Table structure for table 'high_scores'
#
CREATE TABLE high_scores (
id int(11) DEFAULT '0' NOT NULL auto_increment,
name varchar(30),
answer_count int(11),
credit double(16,4),
PRIMARY KEY (id)
);


Re: [PHP] Quotes in Heredoc

2011-02-26 Thread Ashim Kapoor
Yes, in HTML the quotes are optional, but they are required in XHTML
documents:

> http://www.w3.org/TR/xhtml1/diffs.html#h-4.4
>

Ok Thank you,
Ashim


Re: [PHP] Quotes in Heredoc

2011-02-26 Thread Ashim Kapoor
The quotes you mention are in the HTML, nothing to do with PHP. HTML will
work without the quotes in most cases (unless there's a space in the value
for the attribute) but the quotes are required in XHTML and will cause
unexpected results.

Can you elaborate on the XHTML part? Do you mean they are required in XHTML
but optional in HTML ?

Many thanks,
Ashim.


[PHP] Quotes in Heredoc

2011-02-26 Thread Ashim Kapoor
Dear All,

I am learning PHP by reading a book. My query pertains to the following
lines : -

$form_str = <<< EOFORMSTR





.

My query is that is it true that we don't need to do


ie. we don't need to quote the value of the options in Heredoc. Is that
correct?

Many thanks,
Ashim.


Fwd: [PHP] HTTP Authenticaion Query

2011-02-20 Thread Ashim Kapoor
-- Forwarded message --
From: Ashim Kapoor 
Date: Mon, Feb 21, 2011 at 12:46 PM
Subject: Re: [PHP] HTTP Authenticaion Query
To: Peter Lind 



You are tired and not thinking straight. HTTP is a stateless thing: 1.
> you request the page, but you're not authorized, hence you hit the
> first part of the if. PHP does not wait for you to do anything, it
> just runs through the script and sends back a page to you. 2. You
> enter your auth details, once again requesting the same page. 3. PHP
> now sees the auth header sent by your browser, hence hits the second
> part of the if.
>
> Suppose I press Cancel, I would enter the 1st part of the if ,why is the
header not sent again ?
Also how long will this authentication last? I tried closing my browser and
reloading the script and it still shows it as authorized.

Many thanks,
Ashim


[PHP] HTTP Authenticaion Query

2011-02-20 Thread Ashim Kapoor
 Hello {$_SERVER['PHP_AUTH_USER']}.";
echo "You entered {$_SERVER['PHP_AUTH_PW']} as your password.";
}
?>

Dear All,

Above is a code example from php.net
http://php.net/manual/en/features.http-auth.php

What I am left wondering is the SEQUENCE OF FLOW of logic here. Assume a
page has ONLY this code. Then the 1st time the if condition will branch into
if part ( and not the else ) . Then it will send a header and ask for a
username/password pair. When I enter that it is STILL in the IF part. How
will it jump to the else part and authorize me UNLESS when I press enter it
reloads the page. Maybe I am tired and not thinking straight. Would love to
hear a clarification on this.

Thank you,
Ashim


[PHP] Correct file permissions for a website

2011-02-15 Thread Ashim Kapoor
Dear All,

The book PHP and MySQL bible says that the php directory should be world
executable  ? I remember posting a different question earlier to this list
and one person suggesting this and another person replying that that was
incorrect.

Could someone clear the smoke on this one ?

Many thanks,
Ashim.


[PHP] Re: using BOTH GET and POST in the same page.

2011-02-13 Thread Ashim Kapoor
OK. Thank you Jim/Nathan.

Ashim : )

On Sun, Feb 13, 2011 at 1:26 AM, Nathan Rixham  wrote:

> Ashim Kapoor wrote:
>
>> Dear All,
>>
>> I am reading "PHP5 and MySQL Bible". Chapter 7 of the book says that PHP
>> can
>> use GET and POST in the SAME page! Also it says that we can use the SAME
>> variables in GET and POST variable sets and that conflict resolution is
>> done
>> by variable_order option in php.ini Can some one write a small program to
>> illustrate the previous ideas?  It is not clear to me as to how to
>> implement
>> this.
>>
>
> I noticed you've already received one response, so here's some more
> background info.
>
> It's using $_GET and $_POST in the same script, not HTTP GET and HTTP POST.
> $_GET in PHP correlates to the query string parameters in the URL requested,
> $_POST in PHP correlates to form data which is POSTed to the server inside a
> message, with the type application/x-www-form-urlencoded.
>
> One could say that $_GET and $_POST are named misleadingly, and that infact
> what you have is $_PARSED_QUERY_STRING_FROM_URL and $_POST_DATA_MAYBE .
>
> The two are quite separate and can both be used at the same time.
>
> HTML forms allow a method to be set, GET or POST, if GET then the form is
> treated like an URL construction template, if POST then it's treated like a
> message body construction template.
>
> It's worth reading up on both HTTP and HTML Forms when using PHP, since PHP
> is a "Pre Hypertext Processor" and HTTP is the Hypertext transfer protocol,
> and HTML is the Hypertext markup language :)
>
> Best,
>
> Nathan
>


[PHP] using BOTH GET and POST in the same page.

2011-02-11 Thread Ashim Kapoor
Dear All,

I am reading "PHP5 and MySQL Bible". Chapter 7 of the book says that PHP can
use GET and POST in the SAME page! Also it says that we can use the SAME
variables in GET and POST variable sets and that conflict resolution is done
by variable_order option in php.ini Can some one write a small program to
illustrate the previous ideas?  It is not clear to me as to how to implement
this.

Many thanks,
Ashim.


[PHP] Difference between CURLOPT_URL and wget

2011-01-22 Thread Ashim Kapoor
Dear All,

I am a beginner at PHP. I was studying the curl library and I came across
CURLOPT_URL.I think this can be used similar to wget ? What would be the
major differences in these 2 ?

Thank you,
Ashim


Re: [PHP] Newbie looking for a project

2010-11-08 Thread Ashim Kapoor
Dear Tedd,

I have read one php book cover to cover, I wanted to contribute to projects
for 2 reasons:-

1. Someone would benefit from the app.
2. I would learn more by interacting with experienced people.

Writing apps on my own is fun but it's fruit is only for me to benefit
from,but yes if nothing else I should do that.

Many thanks for your time,
Ashim.




On Sun, Nov 7, 2010 at 8:21 PM, tedd  wrote:

> At 3:39 PM +0530 11/7/10, Ashim Kapoor wrote:
>
>> Dear All,
>>
>> I am a beginner looking for a project to contribute. Can someone tell me
>> some good quality projects where I would learn the most? I hope this is
>> the
>> right forum for this query.
>>
>> Many thanks,
>> Ashim Kapoor
>>
>
> Hi Ashim:
>
> When I started programming php/mysql,  I purchased as many books as I could
> and went through each one creating demos of everything I found.
>
> I still read at least one book every two weeks (or so my expense statement
> reads) and my demos have gotten more complex incorporating more than
> php/mysql (i.e., javascript, jquery, css, etc.)
>
> Now I have a considerable amount of demos and when I need something, I have
> a great store of example to draw on.
>
> Cheers,
>
> tedd
> --
> ---
> http://sperling.com/
>


[PHP] Newbie looking for a project

2010-11-07 Thread Ashim Kapoor
Dear All,

I am a beginner looking for a project to contribute. Can someone tell me
some good quality projects where I would learn the most? I hope this is the
right forum for this query.

Many thanks,
Ashim Kapoor