0

I am really pounding my head on the desk about this:

I am saving session data on page1.

here is the initial code:

<?php
session_start();

$SID = session_id();

$newToken = md5(uniqid(mt_rand(), true)); 
$_SESSION['donate-token'] = $newToken;

I did a var dump at the bottom of page1 so I can see that the session data is saved.

I then checked the server file system and verified that the session file is in place and the data is stored in it.

here is the start of page2 (with some added debugging code):

<?php
session_start();
echo '<pre>';
echo 'session id: ', session_id(), "\n";

$sessionfile = ini_get('session.save_path') . '/' . 'sess_'.session_id();
echo 'session file: ', $sessionfile, ' ';

var_dump($_SESSION);
echo "</pre>\n";

so what I see at the top of this page is a very different session id, and an empty session array.

I can't figure out why one page can write the session but the next one can't read it!

dzogchen
  • 383
  • 3
  • 10

2 Answers2

0

Try adding an exception before calling the session_start() on page2. Try this:

$a = session_id();
if(empty($a)) session_start();
Karl
  • 595
  • 1
  • 10
  • 31
  • I tried it again after a server reboot, and it worked - not sure if it was the reboot or the code, but I ain't gonna change a thing..... – dzogchen Jan 09 '13 at 20:54
  • Glad it worked out for you @dzogchen. Good luck with your project – Karl Jan 09 '13 at 22:15
0

Check out the cookie the script is sending to your browser. (Most browsers have built-in tools to inspect the cookies they hold. You can usually search by domain, e.g. localhost if you're developing on your own system.)

If the cookie is not stored on your browser, check your browser's security settings; if the cookie is stored, but has a path that is not available to the second page, then either look into configuring your session cookie into a less restrictive path or put the two scripts into the same directory.

asmecher
  • 1,055
  • 7
  • 12