Trouble with reading session variables ina new page

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
benireland
Forum Newbie
Posts: 1
Joined: Sat Apr 12, 2003 10:44 am

Trouble with reading session variables ina new page

Post by benireland »

Ok I'm pretty much a novice to this! I installed the latest Apache, PHP and MYSQL to my PC running XP. I have been happily learning PHP/SQL from a fat book for several months and have learnt alot. Initial I didn't know how and then didn't get round to turning global_variables to 'on' in the c:\php\php.ini file. (To pass variable page-to-page I have been using: $_GET['var_name']).
Today I saved the file with this as 'on' but even afte a OS reset it hasn't made a difference that i've noticed w.r.t. collecting post/get form variables.

Now I am learning to use session variables. Which seem pretty straight forward but after I have set a login session variable (to allow personalised page content) my pages just won't detect the session variable even though I pulled the code out of a book.

I'd really appreciate it if someone could point out my error or at least a way I can narrow down the possible promlem. Here's the code;-

//////// extranct from login.php

{after I have valid dated the entered login details}...
if (session_is_registered("valid_user")){
echo "you are now logged in as: $valid_user <br>";
echo "<a href=\"logout.php\"> Log out </a> <br>";
}
<a href="cal_front.php"> Members section </a>
... {At this stage the session variable is the correct value and this if proved in the echoed text. Then if we look at the file it links to;

//////// extracts from cal_front.php
<?
session_start();
if (session_is_registered("valid_user")){
echo "A valid_user value is found in sess vars <br>";
}
else{
echo "Warning: No valid_user in the sess vars <br> ";
}

...{ but this time on a new page it doesn't detect this sess var.}

Can anyone help a desparate guy???? My wild guess might be to do with the way I set (or rather did not set up) the server completely. Although just about everything else has worked.
Thanks very much
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

If you've just started learning PHP keeping registered_globals off and learning how to use $_GET, $_POST et. al. is much better than having register_globals on.

For doing user logins with sessions have a look at:
viewtopic.php?t=6521

Mac
Post Reply