如何禁用PHP会话cookie? [英] How to disable PHP session cookie?

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

问题描述

我正在编写PHP代码,我想使用POST自己传递会话ID.我不希望使用Cookie来存储会话,因为当用户退出POST周期时,它应该会丢失.

I am writing PHP code where I want to pass the session id myself using POST. I don't want a cookie to store the session, as it should get lost when the user gets out of the POST cycle.

PHP会在可用时自动设置cookie.我了解到可以通过将php.ini中的session.use_cookies设置为0来更改此行为.不幸的是,我无权访问该文件,也不想破坏同一服务器上运行的其他脚本的行为.

PHP automatically sets the cookie where available. I learned it is possible to change this behaviour by setting session.use_cookies to 0 in php.ini. Unfortunately, I don't have access to that file and I also wouldn't want to break the behaviour of other scripts running on the same server.

是否可以禁用或禁用PHP脚本中的会话cookie?

Is there a way to disable or void the session cookie inside the PHP script?

编辑:由于建议的解决方案对我不起作用,因此我在代码中发现会话无效的位置上使用了$ _SESSION = array().

As the proposed solutions don't work for me, I used $_SESSION = array() at positions in the code where I found the session should be invalidated.

推荐答案

可以通过创建自己的.htaccess文件来覆盖主机的默认设置,如果您还没有接触过的话,这是一个很好的教程 http://www.askapache.com/htaccess/apache-htaccess.html

err its possible to override the default settings of your host by creating your own .htaccess file and here's a great tutorial if you havent touched that yet http://www.askapache.com/htaccess/apache-htaccess.html

或者如果您懒得学习 只需在您的站点目录上创建一个".htaccess"文件(是文件名)并放置以下代码

or if you're too lazy to learn just create a ".htaccess" file (yes that's the filename) on your sites directory and place the following code

SetEnv session.use_cookies='0';

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

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