By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

mssing session variable in other page

P: n/a
I am the newbie in php
I have a problem about the session variable
When I create the session and session variable,
the variable is set in page 1, but in page 2 the variable is unset
and I don't know why.
I have searched a lot of tutorial, I followed all the steps but still
not work
Can anybody help me!!~
Thank you in advanced
I have created following code
page1.php:

<?php
session_start();
$_SESSION["test"] = "hello";
echo $_SESSION['test'];
header("Location: page2.php");
?>

page2.php

<?php
session_start();
if( !isset($_SESSION['test'])){
echo "The variable is not set
}
?>

The output:
page 1: hello
page 2: The variable is not set

Aug 13 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
garks wrote:
I am the newbie in php
I have a problem about the session variable
When I create the session and session variable,
the variable is set in page 1, but in page 2 the variable is unset
and I don't know why.
I have searched a lot of tutorial, I followed all the steps but still
not work
Can anybody help me!!~
Thank you in advanced
I have created following code
page1.php:

<?php
session_start();
$_SESSION["test"] = "hello";
echo $_SESSION['test'];
header("Location: page2.php");
?>

page2.php

<?php
session_start();
if( !isset($_SESSION['test'])){
echo "The variable is not set
}
?>

The output:
page 1: hello
page 2: The variable is not set
Turn on all errors and enable error reporting to the display.

It's best to do it in the php.ini file. However, you can also add these
to your code as the first things in the file:

error_reporting(E_ALL);
ini_set('display_errors', '1');

That should help you find your problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 13 '07 #2

P: n/a
Thanks for your help~
The following warnings are shown~
How do I correct them?
I don't know how to start the correction
Thank you in advanced.

Warning: session_start() [function.session-start]: open(/var/lib/php/
session/sess_9q770lvt0o29f7h8kb81ng97k5, O_RDWR) failed: Permission
denied (13) in /usr/local/apache2/htdocs/page2.php on line 4
The variable is not set
Warning: Unknown: open(/var/lib/php/session/
sess_9q770lvt0o29f7h8kb81ng97k5, O_RDWR) failed: Permission denied
(13) in Unknown on line 0

Warning: Unknown: Failed to write session data (files). Please verify
that the current setting of session.save_path is correct (/var/lib/php/
session) in Unknown on line 0
Aug 13 '07 #3

P: n/a
/var/lib/php/session <- is valid path

I have checked the files in this path
It seems that the sess_9q770lvt0o29f7h8kb81ng97k5 has not been created
in the /var/lib/php/session
Aug 13 '07 #4

P: n/a
garks wrote:
/var/lib/php/session <- is valid path

I have checked the files in this path
It seems that the sess_9q770lvt0o29f7h8kb81ng97k5 has not been created
in the /var/lib/php/session

It means the userid Apache is running under doesn't have permission to
access this directory.

However, session information is generally stored in /tmp. I'd suggest
you use it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 13 '07 #5

P: n/a

It works after I changed the session_save_path to /tmp

Thank you for your help~


Aug 13 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.