php.ini中的session.cookie_domain-POST表单问题 [英] session.cookie_domain in php.ini - issues with POSTing forms

查看:81
本文介绍了php.ini中的session.cookie_domain-POST表单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主域: www.domain.com 有一个cookie,该cookie设置为: domain.com

My main domain: www.domain.com has a cookie which is set as: domain.com.

用户单击链接访问 www.domain.com/login ,然后他们尝试登录(通过POST请求),此表单会将Cookie设置为 www.domain.com (添加www)。这引起了许多人的问题,因为当他们提交登录表单时,页面会刷新。

Once a user clicks the link to visit www.domain.com/login, and they try to log in (through a POST request), this form sets the cookie as www.domain.com (adds the www). This is causing issues with many people because when they submit the login form, the page just refreshes.

对于某些人,它会永远这样做(永远无法提交表单) 。对于其他人,它只有一次-第二次,它可以正常工作。它也因浏览器而异...

For some people, it does this FOREVER (can never submit the form). For others, it's only once - and the 2nd time, it works fine. It also varies by browser...

这里的解决方法是,我假设我需要在php中的 session.cookie_domain中输入一些内容。 ini -但是正确的处理方法是什么?

What is my fix here, I assume I need to enter something into my session.cookie_domain in php.ini - but what is the correct course of action?

谢谢。

--- 更新 ---
用于在登录页面上设置cookie的代码:

---UPDATE--- Code to set the cookie on the login page:

$expireTime = 60 * 60 * .5; // 30 minute expire time
session_set_cookie_params($expireTime,"/");
session_start();


推荐答案

您需要明确设置域不带www的www,但带有前一个点作为该函数的第三个参数。

You need to explicitly set the domain, without the www, but with the preceding dot, as the third param to that function.

session_set_cookie_params($ expireTime, /, .yourdomain。 com);

session_set_cookie_params($expireTime,"/", ".yourdomain.com");

无论实际URL中是否存在www,cookie都可以相同地工作。请注意,这也适用于您可能使用的任何其他子域,将其放在那里通常是一件好事。

This will allow the cookies to work the same regardless of whether the www is present in the actual URL or not. Note that this also applies to any other subdomains you may use, which is usually a good thing, just putting it out there.

这篇关于php.ini中的session.cookie_domain-POST表单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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