-1

Here's the code

<?php print_r(session_get_cookie_params()); session_set_cookie_params(3600, "/", "mydomain.com");

When I refresh the page, the above parameters are not saved

session_start(); var_dump($_SESSION); $_SESSION['name'] = "name";

When I refresh the page, the above variable is not saved

var_dump($_SESSION); print_r(session_get_cookie_params());

However, both variable and parameters are correctly displayed on first page load.

?>

The first var_dump ALWAYS returns an empty array, the second successfully returns the "name" within it.

$_SESSION variables only ever last one page load.

I have tried naming the session, adding a (long) timeout, linking to a different page, but $_SESSION variables only ever last one page load.

Must this be a problem with the server?

Tzshand
  • 1,575
  • 11
  • 14

2 Answers2

2

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!';
}

This is from a previous post : PHP Session not Saving

Community
  • 1
  • 1
binaryNomad
  • 336
  • 2
  • 6
0

if you use memcache/redis/mysql session storage backend, it can be down. Is there any errors shown? Try to enable error reporting in PHP.ini and rerun the code.

Probably you have put some html output before session_start() and this prevents from setting the session.

vodolaz095
  • 6,680
  • 4
  • 27
  • 42