خرید بک لینک

Vote count: 0

I have a rather strange problem; there are three pages which are using this cookie - one sets $_SESSION = 0 (as another Stack article suggested my issue might be related to PHP having difficulties with timings so 'pre-creating' the session, then writing to it might help), another file starts the session, changes the session cookie to an array with some useful data in it and supposedly saves it. Only, in this file the session will never actually get written to disk... On the third page, I will try and access the cookie and get an output of '0' (first page).

I've spent a lot of time debugging this and have checked:

  1. That session_start and session_write_close are being used appropriately.
  2. That PHP.ini is set up correctly, with a writable storage path (/tmp)
  3. That PHP is actually using this storage path!
  4. And I've also sat there comparing cookie ID's in browser and on the server to work out when sessions are and are not being created.

I don't see an issue in my code, and as other pages are able to use the session correctly (pages 1 and 3), it is only page 2 which is having an issue.

This is my debugging output from page two, showing the array I tried to write plus the fact that PHP doesn't seem to know what the session ID is, but there are no errors when I call session_start? page two debugging output

And the pertinant code from page two:

<?php
//session starts
session_name("oscar");
session_start();
//error reporting
ini_set("display_errors", 1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$_SESSION['user'] = $_POST['username'];
$_SESSION['time'] = time();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];

echo '<pre>';
echo 'session id: ', session_id(), "n";

$sessionfile = ini_get('session.save_path') . '/' . 'sess_'.session_id();
echo 'session file: ', $sessionfile, ' ';
if ( file_exists($sessionfile) ) {
    echo 'size: ', filesize($sessionfile), "n";
    echo '# ', file_get_contents($sessionfile), ' #';
}
else {
    echo ' does not exist';
}

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

session_write_close();

exit();
?>

Thank you for any help - I hope I'm not being stupid. I've made a lot of effort debugging this.

asked 34 secs ago

برچسب: php session not being saved between pages,php session not being saved,php session variables not being saved, نویسنده: استخدام کار تاريخ: چهارشنبه 10 شهريور 1395 ساعت: 18:49

صفحه بندی