標題后PHP會話被破壞/丟失

[英]PHP session destroyed / lost after header


I've got a script that sets some session values before redirecting to / using header().

我有一個腳本,在重定向到/使用header()之前設置一些會話值。

I've read many posts about the $_SESSION variable being destroyed / lost after header(), even after I implemented this:

我讀過很多關於$ _SESSION變量在header()之后被銷毀/丟失的帖子,即使我實現了這個:

// set session here

session_regenerate_id(true);
session_write_close();
header("Location: /");

session_start() is set in the correct places, does anyone know of anything that I might be missing?

session_start()設置在正確的位置,是否有人知道我可能遺失的任何內容?

On the index.php page I have this:

在index.php頁面上我有這個:

session_start();
print_r($_SESSION);

// outputs nothing :'(

The code is pretty complex so will not post it all, just snippets.

代碼非常復雜,所以不會發布所有內容,只是片段。

6 个解决方案

#1


11  

I've never seen any session related issues due to using location headers - are you sure you're calling session_start on both pages?

由於使用了位置標題,我從未見過任何與會話相關的問題 - 您確定要在兩個頁面上調用session_start嗎?


Hmm... this answer made a lot more sense before you added the session_start bits above, and mentioned the fact that you were sure you were using session_start. :-)

嗯......在你添加上面的session_start位之前,這個答案更有意義,並且提到了你確定使用的是session_start。 :-)

#2


5  

header must be sent before session close

必須在會話結束前發送標頭

session_regenerate_id(true);

header("Location: /");
// the header must be sent before session close
session_write_close(); // here you could also use exit();

#3


4  

just put exit; after header :D I solved by this

剛出口;標題后:D我解決了這個問題

#4


4  

After the Header redirect you need to exit the PHP script:

在Header重定向之后,您需要退出PHP腳本:

header("Location: /");
exit();

#5


3  

In the interest of closing this question, we had concluded it was a problem with the server configuration, not surprising considering the host is well known for this kind of thing.

為了解決這個問題,我們得出的結論是服務器配置存在問題,考慮到主機因這類問題而眾所周知,這並不奇怪。

#6


-4  

You don't need to start session_start() in each page. cuz untill your browser is closed the same session remains for the entire path you have specified in php.ini

您不需要在每個頁面中啟動session_start()。因為你的瀏覽器已關閉,所以你在php.ini中指定的整個路徑保持相同的會話


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/01/10/195a6e0f1432caee20c7b01276447eab.html



 
  © 2014-2022 ITdaan.com 联系我们: