Session variables are not being passed from page to page.
on page1.php i have:
session_start(); session_register('hello'); $hello = "hello world";
on page2.php i have:
session_start(); echo $hello;
the output is:
Notice: Undefined variable: hello in c:\my documents\thejlp\profiles\editprofileshome.php on line 3
What am i doing wrong?
not sure what version of PHP you are using, but try this instead:
page 1:
session_start(); $_SESSION['hello'] = "Hello World!";
page 2:
session_start(); echo $_SESSION['hello'];
that's the way I've been instructed to do it.
i need to assign a value to hello later on in the document. for example:
session_start(); session_register('hello'); if ($x == 1) { $hello = "hello world"; } else { $hello ="Goodbye"; }
in other words i need it to be more dynamic
i also jsut got the following error after not changing anything:
Warning: Unknown(): Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0
AH HA! i got it.
in php.ini
register_globals was turned off
Wrong answer! See http://www.php.net/manual/en/security.globals.php and go back to sneakyimp's suggestion.
The manual Use of $_SESSION (or $HTTP_SESSION_VARS with PHP 4.0.6 or less) is recommended for improved security and code readability.
I dont understand what you mean by 'wrong answer'. I turned register_globals back on and it works fine now.
using register globals creates a security problem. read the link he sent.
using the $_SESSION i suggested is more secure AND it makes it more obvious that you're using session variables.
ultimately you can do what you want.