-
Sessions Help
I am working on my register page.
I start the session at the top of my php file:
Code:
<?php
// Lets start the session
session_start();
After form/data validation I create some session variables ($username comes from the HTML textbox and $insertedId comes from a select statement):
Code:
// Lets set a few session variables
$_SESSION['userName'] = $username;
$_SESSION['userId'] = $insertedId;
Once sesssion variables are set I change locations to another php file:
Code:
// Lets get out of here ...
header("Location: home.php");
now, I am in home.php and I try to print my session variables:
Code:
<?php
echo "userName=". $_SESSION['userName'];
echo "userId=". $_SESSION['userId'];
?>
This is the error message I get:
Notice: Undefined variable: _SESSION in C:\wamp\www\TheLastPick\home.php on line 45
userName=
Notice: Undefined variable: _SESSION in C:\wamp\www\TheLastPick\home.php on line 46
userId=
Any idea why my session variables aren't accessible in home.php?
Many thanks for any help.
-
Re: Sessions Help
you need to be using session_start() on every page that uses sessions. this function also resumes sessions, and doesn't just begin them. just place that at the top of your home.php page and everything should be fine.
-
Re: Sessions Help