Re: [PHP] Declaring variables from the url

2006-08-07 Thread Richard Lynch
On Mon, August 7, 2006 8:13 am, Dave M G wrote:
> I have many times set the value of a variable by declaring it in the
> URL, like so:
>
> http://www.domain.com/index.php?var=1
>
> And then, to use the variable, all I have to do is use it in the
> script,
> like so:
>
> echo "This is the value of the variable: " . $var;
>
> But, for some reason, in a script I'm writing now, this simple process
> isn't working.
>
> The only thing I can think of that is different between before and now
> is that the new script is being executed in PHP5, whereas before was
> with PHP4.
>
> In my new script, I check the value of $_SERVER['QUERY_STRING'], the
> value is contained in there, so it is being assigned and contained
> somehow.
>
> What could I possibly be missing in what should be a super simple
> process?

http://php.net/register_globals

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Declaring variables from the url

2006-08-07 Thread Andrei
Also check in php.ini register_globals to be On if you want to have vars
directly available in the script...

Andy

Jay Blanchard wrote:
> [snip]
> http://www.domain.com/index.php?var=1
> 
> And then, to use the variable, all I have to do is use it in the script,
> 
> like so:
> 
> echo "This is the value of the variable: " . $var;
> [/snip]
> 
> echo $_GET['var'];
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Declaring variables from the url

2006-08-07 Thread Jim Moseby
> PHP list,
> 
> I have many times set the value of a variable by declaring it in the 
> URL, like so:
> 
> http://www.domain.com/index.php?var=1
> 
> And then, to use the variable, all I have to do is use it in 
> the script, 
> like so:
> 
> echo "This is the value of the variable: " . $var;
> 
> But, for some reason, in a script I'm writing now, this 
> simple process 
> isn't working.
> 
> The only thing I can think of that is different between 
> before and now 
> is that the new script is being executed in PHP5, whereas before was 
> with PHP4.
> 
> In my new script, I check the value of $_SERVER['QUERY_STRING'], the 
> value is contained in there, so it is being assigned and 
> contained somehow.
> 
> What could I possibly be missing in what should be a super 
> simple process?

To expand on Jay's excellent advice, you have been depending on "register
globals" to set the variable names for you.  This is widely regarded as a
bad practice, because you don't know for sure where $var came from.  You
should ALWAYS use $var=$_GET['var'] when taking values from the url to set a
variable.

For more information on the evils of register globals, STFA.  There have
been many discussions in this list on that topic.

JM  

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Declaring variables from the url

2006-08-07 Thread Jay Blanchard
[snip]
http://www.domain.com/index.php?var=1

And then, to use the variable, all I have to do is use it in the script,

like so:

echo "This is the value of the variable: " . $var;
[/snip]

echo $_GET['var'];

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php