Page 1 of 1
Session Problems
Posted: Tue Jun 24, 2003 7:33 pm
by php_wiz_kid
Here's the problem. I can't seem to get any sessions to work. I've tried making my own, I've tried the sessions I got on CDs that came with some books. None of them are working. This makes me think it's something on my local machine. Does anybody have any idea to what this problem could be? I'm pretty new to PHP and MySQL, but I think I'm getting pretty good at it, so please be patient with me.
Posted: Tue Jun 24, 2003 7:36 pm
by nielsene
How are they not working? Are you receiving error messages?
Posted: Tue Jun 24, 2003 7:41 pm
by php_wiz_kid
No, not error messages. The session variables just don't seem to follow from page to page. So I set the variable on one page, and send it to another and the variable is empty. I use the session_start() function, and the $_SESSION global variable. I figure that I have something wrong setup in the php.ini file or something, but I havn't messed with anything that has to do with sessions in the file.
Posted: Tue Jun 24, 2003 7:47 pm
by php_wiz_kid
Here's an example:
page1.php
<?php
session_start();
$_SESSION['valid_user'] = 1;
echo "The user identification number is $_SESSION['valid_user']";
?>
<a href="page2.php">Page 2</a>
page2.php
<?php
session_start();
echo "The user identification number is $_SESSION['valid_user']";
?>
Now, the variable on page2.php would show up empty. It would say "The user identification number is", and then it will just stop. Now this is off the top of my head so I'm hoping it's right.
Posted: Tue Jun 24, 2003 7:47 pm
by nielsene
Can you post some sample code?
Posted: Wed Jul 02, 2003 9:23 pm
by patchesthedog
Look at the Apache error log to see if you are getting any errors when you try to start a session.
If the directory to post session information is not set up correctly, you can still create sessions, but the data that you associate with the session cannot be stored.
I ran into this problem when I started playing around w/ PHP and after I changed the PHP.INI (I'm in a windows environment) to point to a valid directory for session information (I used, 'C:\APACHE GROUP\APACHE2\TMP') then things began working correctly.
Posted: Thu Jul 03, 2003 9:45 am
by m3rajk
how do you move from page to page?
Posted: Thu Jul 03, 2003 9:52 am
by liljester
i would check the php.ini file, you may need to fix your session temp dir, or somehting like that.
also set "display_errors = On;" to make sure you're not getting any unreported errors =)
Posted: Thu Jul 03, 2003 10:26 am
by Jean-Yves
Have you tried displaying the value outside of the main string quotes:
Code: Select all
echo "The user identification number is " . $_SESSIONї'valid_user'];
I got a parse error when I tried it the way it was before (ie inside the main quotes).
Posted: Thu Jul 03, 2003 10:56 am
by php_wiz_kid
Thanks everybody, I now have my sessions working. I had to change the php.ini to make it work. Again, thanks to everyone who posted.