0

Through this post and this post,php 5.4 in my centos7 server is Cookies OFF.
Test script as below:

<?php
if (isset($_GET['cookiecheck'])) {
    if (isset($_COOKIE['testcookie'])) {
        print "Cookies ON";
    } else {
        print "Cookies OFF";
    }
} else {
    setcookie('testcookie', "testvalue");
    die(header("Location: " . $_SERVER['PHP_SELF'] . "?cookiecheck=1"));
}
?>

Then,I began to looking for reason(no any apache error log,just cannot use cookie).
phpinfo() result seemed no problem:
Untitlee4d.png

In session.save_path, /var/lib/php/session,I can find some fresh files:

-rw------- 1 apache apache    7 Jan 21 10:34 sess_1bigb6qbcj3n09430h4ds6od02
-rw------- 1 apache apache    7 Jan 21 10:22 sess_407mq9gfd50jg4qeo6jededej3
-rw------- 1 apache apache    7 Jan 21 10:27 sess_5fg4og04vrqdbda3080mrnm9o3
-rw------- 1 apache apache    7 Jan 21 10:22 sess_6pnsa9ico2cppnl0ttbv83acn5
-rw------- 1 apache apache    7 Jan 21 10:24 sess_8gn7v82gf5cnhgvtmi8p01hb81
-rw------- 1 apache apache    7 Jan 21 10:22 sess_dbfa93el78h8s7m4f5hvojj0b4
-rw------- 1 apache apache    7 Jan 21 10:22 sess_i0r2k5ufb1eg2s205v1s3h62b5
-rw------- 1 apache apache    7 Jan 21 10:23 sess_kt5hpehhtvgqgncr72vllrtel4

Which means cookie saved in correct path when I run the test script.But I still get Cookies OFF result.

when I vi sess_1bigb6qbcj3n09430h4ds6od02,the content is only page|N;.
Is that means nothing saved?Or something wrong happened?

yivi
  • 42,438
  • 18
  • 116
  • 138
kittygirl
  • 2,255
  • 5
  • 24
  • 52
  • 1
    $a will not equal $b - they will be different session ids as you destroy the session – Professor Abronsius Jan 21 '19 at 07:55
  • @RamRaider,you mean cookie is enabled but I use wrong test script? – kittygirl Jan 21 '19 at 07:58
  • I think your understanding and my understanding of what the "test script" does is different. It looks like cookies are working fine – Professor Abronsius Jan 21 '19 at 07:59
  • 2
    _"cookie saved in correct path when I run the test script"_ - Cookies and sessions are not the same thing. The session save path stores session data. Cookies exists in the client. – M. Eriksson Jan 21 '19 at 08:05
  • @RamRaider,use another `test script`,result still `Cookies OFF`. I think cookie doesn't work fine. – kittygirl Jan 21 '19 at 08:05
  • @MagnusEriksson,`session.use_only_cookies` is `ON`. – kittygirl Jan 21 '19 at 08:08
  • use the console in your webbrowser to inspect the cookies – Professor Abronsius Jan 21 '19 at 08:57
  • That's about using session cookies (which is sent and stored in the client). A session cookie only contains the session id, which then is passed along with every request to the server so the server can read the contents (which are stored on the server in the save_path) and populate the $_SESSION-variable. The list you show in your post is on the _server_ and does _not_ have anything to do with cookies. If you set the `use_only_cookies` to `off`, then PHP will also be able to use sessions from the the GET/POST/URL. – M. Eriksson Jan 21 '19 at 09:02
  • Read more about sessions and the settings [in the manual](http://php.net/manual/en/session.security.ini.php) – M. Eriksson Jan 21 '19 at 09:05

0 Answers0