没有cookie的PHP会话 [英] PHP session without cookies

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

问题描述

有没有方法,我可以在PHP中启动持久会话,而不放置会话cookie?是否还有其他方法来维护跨页面的会话,例如基于IP地址的解决方案?

Is there a way that I can initiate a persistent session in PHP without the placement of a session cookie? Are there other ways of maintaining a session across pages, such as an IP address-based solution?

我的原因是,虽然大多数用户都有Cookie,我想看看是否有一个登录系统的工作对于那些与禁用(即使我认为禁用cookies只是不必要的偏执狂,个人)。

My reason for asking is, is that although most users have cookies on, I want to see if there's a way for a login system to work for those with it disabled (even though I think disabling cookies is just unnecessary paranoia, personally).

推荐答案

我不认为要求用户启用Cookie太多了。

I don't think it's too much to ask your users to enable cookies. I find it silly when people turn them off entirely.

否则,您可以将session.use_only_cookies设置为0,以强制将会话ID附加到网址中的网址你的php。然而,这种方法有几个缺点。主要是保持在URL内的状态,而不是Cookie头。如果用户要复制并粘贴他们所在网页的网址,而有人点击它,则他们都将使用相同的会话。

Otherwise, you can set your session.use_only_cookies to "0" to force the appendage of a session ID to URLs within your php. This approach, however, has several draw backs. Mainly that of keeping the state within the URL, as opposed to the Cookie header. If a user were to copy and paste the URL of the page they were on, and someone else were to click on it, they would both be using the same session.

<?php
     ini_set("session.use_cookies", 0);
     ini_set("session.use_only_cookies", 0);
     ini_set("session.use_trans_sid", 1);
     ini_set("session.cache_limiter", "");
     session_start();

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

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