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!
First of all, I read the session thing on the top of this forum, I copied and paste the code and got a
Notice: Undefined index: username in c:\apache group\apache\htdocs\chapter20\page2.php on line 5
$_SESSION[username] equals
I have researched a lot of places but I still can't get my sesison to work. I changed to the global thing on and off still no luck. I used the session_register() methods and the $_SESSION[] methods, still non of them works. I checked the path and the session files are all there. I either get the undefined index error or undefined variable error. So, would anyone help? I am running php 4.30 with apache 1.3.27 on a win xp pro. I got the Sams "php and mysql web development" book as a reference. Would someone please help me here.(Haven't slept for 2 days just trying to figure out what is going on) THNX~
php manual wrote:Caution
If you want your script to work regardless of register_globals, you need to use the $_SESSION array. All $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where register_globals is disabled.
AND
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister().
Thank you for your time, but I have learned to use $_SESSION[] as well, still my problem does not go away. I had an interesting discovery though. When I access the page1.php, a session file containing the session variable is created. When I access the page2.php from page 1, an empty session file is created. Is this normal??
echo '$_SESSION[username] equals '.$_SESSION['username'];
echo "<br>\$ses is ".$_SESSION['ses'];
echo '<br><br><a href="page2.php">Go to page 2</a>';
?>
page2.php
<?php
session_start();
if(!isset($_SESSION['username'])){
echo "session not set<br>";
}
if(!isset($_SESSION['ses'])){
echo "\$ses not set<br>";
}
// If session vars are set, display vars
if(isset($_SESSION['username'])){
echo "The session vars are set <br>";
echo "\$ses = ".$_SESSION['ses']."<br>";
echo "Username is ".$_SESSION['username']."<br>";
}
?>
FINALLY WORKING!!!
I re-intsalled apache 1.3.27 with source and the latest PHP 4.3.2rc
and I see my FIRST SESSION variable appear on the next page!!!!
THANK YOU..I AM SO HAPPY~