Paul wrote:

Probably a stupid question.

I figured I could do something like $_SESSION['test'] = 5 and refer to $test
on other pages however I cannot. The reason I thought I could do this is
because I can do $_SESSION['test'] = $_POST['test'] and be able to refer to
just $test on other pages.

Is the correct way to do this to make sure that I have somewhere
session_register['test']


Thanks!

It is true that you should be able to use $test to access the session var in other pages, but only if you have register_globals on and you have called session_start().


$_SESSION['var'] = 1;
is the same as
$var = 1;
session_register('var');

However, it's never a good idea to rely on globals because:
1) The variable could come from the session, POST, or GET and you don't know which one it comes from. Sure, you know the order of precedence (you can even set it yourself in the php.ini), but you still don't know which one was used.
2) Within functions, you don't have direct access to global variables. You can use global $var; but that's *VERY* prone to errors. You can use $GLOBALS['var'] but that's nearly as much typing as $_SESSION['var'] and is far less reliable and secure.


My suggestion is to turn off register_globals (as many others will tell you) and use $_POST, $_GET, $_SESSION, and maybe even $_REQUEST.

--
paperCrane <Justin Patrin>

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



Reply via email to