0

I am trying to use PHP session to store a state that is passed through 1 time via the querystring from a referring website. The trouble is locally I can maintain this state in the session scope but it is not working the same on the production server.

Im trying to do this in Wordpress in wp-config.php at the foot of the file:

session_set_cookie_params(0);
session_start();

Starting a session that expires with the browser. Then checking & setting for the querystring param:

if (!isset($_SESSION['isEUStore']) && isset($_GET['store']) && strtolower($_GET['store'])=='eu') $_SESSION['isEUStore']=true;
elseif (!isset($_SESSION['isUSStore']) && isset($_GET['store']) && strtolower($_GET['store'])=='us') $_SESSION['isUSStore']=true;

However, $_SESSION['isEUStore'] or $_SESSION['isUSStore'] returns NULL on any other Wordpress page in the site.

Any advice? Some configuration setting that is different perhaps?

Thanks,

4

1 回答 1

1

我没有解决会话被遗忘的问题,但我发现使用 cookie 可以代替。如:

if (!empty($_GET['store']) && strtolower($_GET['store'])=='eu') {
    setcookie('isEUStore', true, 0, '/', $faco_domain);
    setcookie('isUSStore', true, time()-3600, '/', $faco_domain);
} elseif (!empty($_GET['store']) && strtolower($_GET['store'])=='us') {
    setcookie('isUSStore', true, 0, '/', $faco_domain);
    setcookie('isEUStore', true, time()-3600, '/', $faco_domain);
}

cookie 不会在 Wordpress 页面之间被遗忘,但会在浏览会话结束时过期。

于 2012-06-20T12:14:03.963 回答