Session variables not working php

后端 未结 10 1334
别跟我提以往
别跟我提以往 2020-11-22 03:12

Here are the code of my login page where the login script checks for the authenticity of the user and then redirects to inbox page using header function.

<         


        
10条回答
  •  情歌与酒
    2020-11-22 03:58

    1. Make sure session_start(); is called before any sessions are being called. So a safe bet would be to put it at the beginning of your page, immediately after the opening tag before anything else. Also ensure there are no whitespaces/tabs before the opening tag.
    2. After the header redirect, end the current script using exit(); (Others have also suggested session_write_close(); and session_regenerate_id(true), you can try those as well, but I'd use exit();).
    3. Make sure cookies are enabled in the browser you are using to test it on.
    4. Ensure register_globals is off, you can check this on the php.ini file and also using phpinfo(). Refer to this as to how to turn it off.
    5. Make sure you didn't delete or empty the session.
    6. Make sure the key in your $_SESSION superglobal array is not overwritten anywhere.
    7. Make sure you redirect to the same domain. So redirecting from a www.yourdomain.com to yourdomain.com doesn't carry the session forward.
    8. Make sure your file extension is .php (it happens!).

    PHP session lost after redirect

提交回复
热议问题