2018-07-05 08:12
浏览 307


I have created a popup in WordPress that will open when visitor IP is from Australia. The popup will show up on page load. I want to make it not show until the browser screen is closed.

For this, I used the cookie. I set the cookie when the close button is clicked and creating the cookie in PHP using ajax.

Here is the code I am using to create cookie:

 setcookie("stay_here", "yes", 0, "/");

I set the cookie time to 0 so that it will destroy when the browser closed. The issue is that the site has user account area and when the user is logged in the session of the user is created. This session is not destroying after closing the browser. And when the above cookie created it automatically set expiration time as "Session".

I checked this on firefox and the data variable "Expires" of the cookie is set as "Session". As the session is not destroying when I close the browser and the cookie Expires value which is set as Session is also not destroying.

But I want the only cookie to be destroyed when the browser is closed not the Session.

I hope you understand my issue.

Can you guys look at the issue and provide me a solution to achieve this situation.

Thanks in Advance.

图片转代码服务由CSDN问答提供 功能建议

我在WordPress中创建了一个弹出窗口,当访客IP来自澳大利亚时将打开该弹出窗口。 弹出窗口将显示在页面加载上。 我希望在浏览器屏幕关闭之前不显示它。

为此,我使用了cookie。 我在单击关闭按钮时设置cookie并使用ajax在PHP中创建cookie。

以下是我用来创建cookie的代码: < pre> setcookie(“stay_here”,“yes”,0,“/”);

我将cookie时间设置为0以便它将 浏览器关闭时销毁。 问题是该站点具有用户帐户区域,并且当用户登录时,会创建用户的会话。 关闭浏览器后,此会话不会破坏。 当上面的cookie创建时,它会自动将到期时间设置为“Session”。

我在firefox上检查了这个,并且cookie的数据变量“Expires”被设置为“Session”。 因为当我关闭浏览器时会话没有被破坏,并且设置为Session的cookie Expires值也没有被破坏。

但是我想在浏览器时销毁唯一的cookie 关闭不是会议。


你能看看这个问题,并为我提供解决方案来实现这一目标。 。


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongmi1864 2018-07-05 08:51

    Ideally cookie created through SETCOOKIE function in PHP with its expire time 0, it will be deleted from browser when you will close the tab and time can't be overwrite with session's cookie time.

    Try to create 1 test.php page and write setcookie("stay_here", "yes", 0, "/"); code and check from browser's cookie information.

    You can also, set session cookie's time to 0 so session cookie will also deleted when browser will be closed.

    ini_set('session.cookie_lifetime', 0);

    解决 无用
    打赏 举报
  • 查看更多回答(2条)

相关推荐 更多相似问题