PHP session control settings

Diana Bodnarescu
2008-04-22 00:35:05
PHP session control settings
Hi,
I have used the code for using session variables:

<?php
session_start();
$username = "demo12";
$_SESSION["userEmail"] = $username;
?>

and on another page

<?
echo $_SESSION["userEmail"];
?>

but it does not display demo12 as is should. It displays nothing.Do you know if I have to change some settings in php.ini to make session control work? The PHP version that I am using is 5.2.4. Thank you!
Veselin
2008-04-22 09:42:29
Re:
do you have
session_start();
on the second page?
Diana Bodnarescu
2008-04-22 10:18:34
Re:
Yes,infact here are the 2 pages codes:

page1.php:

<?php
session_start();
echo "<html><body>";
$username = "demo12";
$_SESSION["userEmail"] = $username;
echo "<a href="page2.php">Next</a>";
echo "</body></html>"
?>
and 2.php:

<?php
session_start();
echo $_SESSION["userEmail"];
?>

What could it be?
Koceto
2008-04-22 10:55:03
Re:
Maybe the problem is with your PHP configuration. Can you check your php.ini file for the following options. Those are the default values:

session.use_cookies = 1
session.auto_start = 0

If you have those set to different values this may cause your problem
Diana Bodnarescu
2008-04-22 11:00:44
Re:
They are set correctly. I red that there also have to be these modifications in php.ini:
session.save_path="C:/Temp"
session.cache_limiter=private
I have not made these modifications yet because there are 3 places where you can find session.save_path
in php.ini and I didn't know where to change it. What do you think?
Diana Bodnarescu
2008-04-22 11:10:33
Re:
And another strange thing happened. I wrote these 2 php pages:

<?php
session_start();
$_SESSION['views'] = 1;
echo "Pageviews = ". $_SESSION['views'];
?>

and

<?php
session_start();
if(isset($_SESSION['views']))
$_SESSION['views'] = $_SESSION['views']+ 1;
else
$_SESSION['views'] = 1;
echo "views = ". $_SESSION['views'];
?>

and the variables were not saved from one page to another. Then I copyed the pages and renamed them and it worked! Same content,different name and it worked..Could the browser be the problem?
Koceto
2008-04-22 11:17:55
Re:
No need to set the session.save_path. Can you check your apache error log. maybe there is something there
Diana Bodnarescu
2008-04-22 11:25:11
Re:
Thank you for your answers so far!
In the Error folder there are a few files that were last modyfied on 13.11.2005. I'm afraid I do not know how to read them (understand them). But I have installed Apache+PHP+MySQL a month ago..
Koceto
2008-04-22 11:39:13
Re:
You have to look for your error log files in
"Apache Install Dir"/logs. There shuold be 3 log files. They are text files. What you are interested in is error.log. Any error taht you get in your PHP is recorded there. Use this file anytime that your page doesn't show up or you get another error.
Diana Bodnarescu
2008-04-22 21:04:43
Re:
It works now. I don't know exactly what the problem was, but now the session variables are saved from one page to another. Thank you! And thanks for the error.log tip also, now it is much easyer to debug the errors. :)
Reply
Title:
Your name:
Your email: (email address will not be posted on the web site)
Reply:
Verification