Page 1 of 1

session_register working but $_session isn't

Posted: Fri Sep 26, 2003 5:59 am
by Dave_will
Using PHP version 4.1.2
Running test.php & test2.php gives the following output.

Current page: A = Page A
Current page: Z =

Why isn't the $_session['current_page_z'] = "Page Z"; working?
I've checked all the documentation...

<?php
// test.php
session_start();
$current_page_a = "Page A";
session_register ("current_page_a");
$_session['current_page_z'] = "Page Z";
$_sid_value = "?" . SID;
?>
<A HREF="test2.php?<?php echo strip_tags (SID)?>">Click here</A>
============================================
<?php
// test2.php
session_start();
print("Current page: A = " . $current_page_a . "<br>");
print("Current page: Z = " . $_SESSION['current_page_b'] . "<br>");
?>
============================================

Posted: Fri Sep 26, 2003 6:39 am
by twigletmac
PHP is case sensitive so $_session is a different variable to $_SESSION, you need to be using $_SESSION to get this to work.

Mac

Posted: Fri Sep 26, 2003 6:42 am
by twigletmac
Another thing, session_register() doesn't tend to play nicely with $_SESSION, so if $_session was a typo when you posted in the forum it is likely that session_register() is preventing the $_SESSION array from functioning correctly.

Mac

Posted: Fri Sep 26, 2003 7:01 am
by Dave_will
Many thanks... a case of me being really stupid

Posted: Fri Sep 26, 2003 7:10 am
by twigletmac
In cases like these it would be nice if there was a level of error reporting at which PHP would give out errors like 'I see you've got $_session - do you perhaps mean $_SESSION', kinda like the way that Google keeps telling me I can't spell :lol:.

Mac

Posted: Tue Sep 30, 2003 7:17 pm
by AnsonM
isnt it

session_register("current_page_a"); ?

Posted: Tue Sep 30, 2003 11:06 pm
by phice
haha, google's the best. :D

Posted: Wed Oct 01, 2003 3:23 am
by twigletmac
AnsonM wrote:isnt it

session_register("current_page_a"); ?
Not any more, session_register() does not work with register_globals off and has been deprecated in favour of the:

Code: Select all

$_SESSION['var'] = 'value';
method of setting session variables.

Mac