Jump to content

Recommended Posts

 

Can't get this to work.  Here's the typical sample code -

 

 

page1.php:

 

<?php

session_start();

$_SESSION['filename']='file.txt';

echo "page 1<br>filename = " . $_SESSION['filename'];

echo "<br><a href='page2.php'>page 2</a>";

?>

 

page2.php:

 

<?php

session_start();

echo "page 2<br>filename = " . $_SESSION['filename'];

echo "<br><a href='page1.php'>page 1</a>";

?>

 

$_SESSION['filename'] echos in page 1, but is blank in page 2.

 

:shrug:

 

 

For debugging purposes, add the following three lines of code starting on the line immediately after your <?php tag in both files -

 

ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(E_ALL);

 

You should actually have the error_reporting/display_errors settings already set to those values on your development system so that php will help you when developing and debugging php code.

 

Here's what I get back -

 

 

Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_a5afedd57f71750eef45b2d5cc870fe4, O_RDWR) failed: No such file or directory (2) in /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php on line 6

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php:6) in /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php on line 6

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php:6) in /xxxxxx/xxxxx/xxxxx/xxxxxxxxxxxxx/xxxxxxx/page1.php on line 6

page 1

filename = file.txt

page 2 //

Warning: Unknown(): open(/var/php_sessions/sess_a5afedd57f71750eef45b2d5cc870fe4, O_RDWR) failed: No such file or directory (2) 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/php_sessions) in Unknown on line 0

 

 

Is that a server problem?

 

 

it means you have the wrong file path for your session folder.

 

Echo this

echo session_save_path();

 

That will give you the actual save path for your session folder.

 

You can also find this info in your php_info() page - - seen when you place

php_info();

 

This will show you all your current server settings.  Also, you should check to be sure the start_session() function is run before ANYTHING else on the page. That may be why you are getting the header sent error... although, i have gotten that error when certain php functions (notably the unlink() function) are trying to send back errors which is why we use the error suppression (@) method.. but this is not likely your issue with the session.

 

If you are in Linux and have access to the file permissions, you may want to open them up a bit more to a chmod 775 or something of the sort.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.