-2

The sessions on my server are being written but are not getting read

the following code used:

<?php
session_start();
if (isset($_POST['submit'])) {
    if(!isset($_SESSION['cheese'])) {
        $_SESSION['cheese'] = 1;
    } else {
        $_SESSION['cheese']++;
    }
}
?>

session_start() creates new session on page reload meaning its not picking up the session. The above code displays no value.

php ini file looks like this for sessions:enter image description here

cheese|i:1; <- this is whats stored in the session

EDIT*****************

Following on from the suggestion to check var_dump($_COOKIE, $_SESSION, $_REQUEST, FILE.LINE); the following is shown on each page

array(0) { } array(1) { ["test"]=> string(2) "hi" } array(0) { } string(36) "/data/vhosts/slacatalogue/sesh1.php5"

Array ( ) array(0) { } array(0) { } array(0) { } string(36) "/data/vhosts/slacatalogue/sesh2.php6"

writing it but not reading it

emma perkins
  • 749
  • 1
  • 10
  • 28
  • 2
    You'll need to show us some code –  Mar 02 '16 at 13:54
  • did you put session_start() on top? – Muhammed Mar 02 '16 at 13:55
  • Sorry forgot to add them into code tags – emma perkins Mar 02 '16 at 13:59
  • 1
    NO WE DO NOT NEED TO SEE SOME CODE - as long as you are calling session_start() and not using a custom session handler, the problem will not be apparent from the code. – symcbean Mar 02 '16 at 14:02
  • How are you maintaining session? Do you have a PHPSID on the URL? As your cookie life is zero, but set to on. Check your browser for a cookie being set, as otherwise there's nothing to link the session on the server, with the browser. – i-CONICA Mar 02 '16 at 14:03
  • @i-CONICA: As per screenshot above, the server is NOT configured to pass session ids in the URL, a cookie TTL of 0 means that its a browser session cookie (a php session is very different from a browser session). – symcbean Mar 02 '16 at 14:11
  • test|s:2:"hi"; <- this is whats stored in the session – emma perkins Mar 02 '16 at 16:12
  • I provided the output as it shows me nothing to debug it - one writes and reads onpage and the other does not read also its just 2 simple pages - the code I provided as all there is to test the sesisons – emma perkins Mar 02 '16 at 16:41
  • i don't have any html forms - i have just coded the php pages to test this out. I am manually creating the session to be $_SESSION['test']='hi'; on one page and trying to call it on anouther. so i open sesh1.php to create the session and go to sesh2.php to try read it – emma perkins Mar 02 '16 at 16:54
  • I dont - i go to my address bar and type in http://intranet/sesh1.php - this loads up the first page PHP Script 1 then i go to a new tab and type in http://intranet/sesh2.php to load up PHP Script 2 to see the script – emma perkins Mar 02 '16 at 17:08
  • Notice there is no session cookie coming back from the web-browser? see the first entry in the `var_dump`? PHP makes a new session. – Ryan Vincent Mar 02 '16 at 17:25
  • Strange - why would it make a new session? – emma perkins Mar 03 '16 at 09:48
  • updated with new code – emma perkins Mar 03 '16 at 12:13

2 Answers2

0

Check with session_save_path() if it is writable.

if (!is_writable(session_save_path())) {
    echo 'Session path "'.session_save_path().'" is not writable for PHP!'; 
}
Nefro
  • 195
  • 1
  • 11
0

The sessions on my server are being written

How do you know? Did you check the files were being modified? Did you check the content?

The most likely cause is that you've not checked your error logs or your error reporting is mis-configured and PHP is unable to send a session cookie to the browser. This should be obvious from the response headers.

If your server is sending the session cookie to the browser, then the next thing to check is whether the browser is sending it back in request headers - most browsers have the option to disable cookies.

If the cookies are working OK, then have a look at the files - are they being updated each time a request lands on a script with session_start()? If not, you may have a permissions problem.

Community
  • 1
  • 1
symcbean
  • 47,736
  • 6
  • 59
  • 94