Page 2 of 2

Posted: Fri Oct 05, 2007 7:44 am
by fakhrizaki
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Following is the code for page1:

Code: Select all

<?php
session_start();
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1); 

$_SESSION['var']='This value is stored in a session variable and should be carried to the page2.';
?>
<html>
<head>
<title>Page 1</title>
</head>
<body>
<?=$_SESSION['var'];?>
<br />
Click to go to <a href="page2.php">page2</a>
</body>
</html>
Code for page2:
===========

Code: Select all

<?php
session_start();

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1); 
?>
<html>
<head>
<title>Page 2</title>
</head>
<body>
<p>Page2 :</p>
<p>
  <strong>Session Value:</strong> 
  <?=$_SESSION['var'];?>
</p>
</body>
</html>
OUTPUT OF PAGE 1:
==============

This value is stored in a session variable and should be carried to the page2.
Click to go to page2

OUTPUT OF PAGE 2:
==============

Page2 :

Session Value:
Notice: Undefined variable: _SESSION in /home/dragonf/public_html/dragonfeed/page2.php on line 15


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Oct 05, 2007 10:48 am
by feyd
The error you are currently receiving suggests the session didn't start as $_SESSION would be defined if it were.

Posted: Fri Oct 05, 2007 10:43 pm
by fakhrizaki
Thanks,

But as far as the code is concerned everything is fine. session_start() is also there and the permissions to the session save path is also OK. Then what could be the reason. I am amazed because sessions were working fine previously and suddenly it stopped working :(

What do you reckon?

Posted: Fri Oct 05, 2007 11:39 pm
by s.dot

Code: Select all

var_dump($a = ini_get('session.gc_maxlifetime'));
Hopefully that doesn't print 0.

Or what about this, to check if the file exists.

Code: Select all

echo file_exists(session_save_path() . DIRECTORY_SEPARATOR . 'sess_' . session_id()) ? 'session file exists' : 'session file does not exist';
Or, maybe you don't have cookies enabled and your session.use_only_cookies is set to false.

Code: Select all

var_dump($a = ini_get('session.use_only_cookies'));

Posted: Sat Oct 06, 2007 8:54 am
by feyd
I suspect it may be more simple. If this is being run on an Apache server, create an .htaccess file in the file's directory. In it, set error_reporting to E_ALL and display errors on. This way you don't have to set it in your files... and certain errors will display, because E_ALL in the code misses some errors which happen before the code begins parsing. http://php.net/configuration.changes for more details.

Rerun these scripts afterward. I suspect there's whitespace before the beginning of the code in the second file.