Home>

I'm using a lollipop server.
I'd like to implement a countup using a session, but I'm having trouble with the count not increasing when I reload the page.
Is there something wrong with the settings or description?
No error message is displayed.

session.auto_start = 1;
Has been set.

Corresponding source code
<? php
session_start ();
ini_set ('session.gc_maxlifetime', 60 * 60 * 24);// 1 day later
$_SESSION ["cnt"] ++;
var_dump ($_SESSION ["cnt"]);
?>
What I tried

// ini_set ('session.gc_maxlifetime', 60 * 60 * 24);// 1 day later
The result did not count up even if it was commented.

if (! isset ($_SESSION)) {session_start ();}
No matter how many times I ran it, the result did not count up.

if (! isset ($_SESSION ["cnt"])) {$_SESSION ["cnt"] = 0;} else {$_SESSION ["cnt"] ++;}
No matter how many times I ran it, the result did not count up.

php
  • Answer # 1

    I created a new file and wrote the exact same process and it worked.
    The cause was that the file was UTF8 (with BOM).
    I was able to confirm that it works by changing to UTF8 (without BOM).

  • Answer # 2

    session_start ();
    ini_set ('session.gc_maxlifetime', 60 * 60 * 24);// 1 day later


    I think the above writing order is reversed.

    ini_set ('session.gc_maxlifetime', 60 * 60 * 24);// 1 day later
    session_start ();


    Please try this.