会话 cookie 和 www [英] Session cookie and www

查看:49
本文介绍了会话 cookie 和 www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在使用 www 时让我的会话在我的网站上工作.并且不使用时.我读过这个线程:PHP cookie 问题 - www 或不带 www

I would like to have my session work in my website when using www. AND when not using it. I've read this thread: PHP cookie problem - www or without www

这行得通,但我不是在这里创建 cookie,而是会话.我将如何解决这个问题?另请注意,我不知道我的脚本将在哪个域上运行,因此无法对域进行硬编码.

And this would work, but I'm not creating cookies here, but sessions. How would I solve this? Also note that I don't know on which domain my scripts will run, so hardcoding the domain is not an option.

有没有办法做到这一点?

Is there a way to do this?

谢谢

我强制会话 ID 应该存储在 cookie 中,因此仅适用于此.

I'm forcing that session ID's should be stored in cookies, so only this applies.

推荐答案

在调用 session_start 之前使用 session_set_cookie_params 函数,它允许您设置会话域和其他东西,将域设置为以 .使会话也可用于子域.

Use session_set_cookie_params function before calling session_start, it allows you to set the session domain and other things, set the domain to your domain prefixed with a . to make the session available to subdomains as well.

这篇关于会话 cookie 和 www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆