Session Problems
Moderator: General Moderators
-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm
Session Problems
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.
-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm
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.
-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm
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.
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.
-
patchesthedog
- Forum Newbie
- Posts: 1
- Joined: Wed Jul 02, 2003 9:23 pm
- Location: Cleveland, OH
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.
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.
Have you tried displaying the value outside of the main string quotes:
I got a parse error when I tried it the way it was before (ie inside the main quotes).
Code: Select all
echo "The user identification number is " . $_SESSIONї'valid_user'];-
php_wiz_kid
- Forum Contributor
- Posts: 181
- Joined: Tue Jun 24, 2003 7:33 pm