Session lost after page redirect in php

前端 未结 7 1304
你的背包
你的背包 2020-11-30 13:52

When I use php header redirection all session variables are lost... Some people say that adding exit(); just after the header(\"\"); will solve the problem but it doesn\'t s

相关标签:
7条回答
  • 2020-11-30 14:24

    You just need to check the file permission in /var/lib/php directory give yje public permisssion to /var/lib/php/session directory.

    and all done.

    0 讨论(0)
  • 2020-11-30 14:25

    You aren't starting the session. In order to use session variables and have them carry across pages, you need to put

    session_start();
    

    at the top of each page before anything else.

    0 讨论(0)
  • 2020-11-30 14:25

    These sessions does not always work as we expect sometimes. I had a similar problem with my website using sessions that get lost. I basically solved it by injecting the value I want to keep on the session into the hidden text field the first time the page loads. Then the second time I call the page(page submit) I simply read the value from the hidden text field and carry on with rest of my code.

    That's more easier and cleaner than using sessions in this case!

    0 讨论(0)
  • 2020-11-30 14:33

    Simples! make sure the page you are coming from (e.g. www.example.com) redirects to a (eg.g www.example.com/redirect.php) notice www at the beginning. If you change that from page to page, then yes things get wonky.

    0 讨论(0)
  • 2020-11-30 14:35

    exit; should be placed after header redirection or session_regenerate_id(true); can be used

    0 讨论(0)
  • 2020-11-30 14:38

    You need to put exit(); after your header redirection, otherwise you have just loaded two pages of content into 1 page.

    Also make sure you have session_start(); at the top of all your scripts.

    0 讨论(0)
提交回复
热议问题