session_register working but $_session isn't

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dave_will
Forum Newbie
Posts: 5
Joined: Mon Sep 22, 2003 4:07 am
Location: UK

session_register working but $_session isn't

Post 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>");
?>
============================================
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Dave_will
Forum Newbie
Posts: 5
Joined: Mon Sep 22, 2003 4:07 am
Location: UK

Post by Dave_will »

Many thanks... a case of me being really stupid
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
AnsonM
Forum Commoner
Posts: 72
Joined: Thu Sep 25, 2003 7:21 am

Post by AnsonM »

isnt it

session_register("current_page_a"); ?
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

haha, google's the best. :D
Image Image
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply