Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable PHP session cookie?

Tags:

php

session

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 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.

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

EDIT: 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.

like image 457
ypnos Avatar asked Oct 27 '08 23:10

ypnos


2 Answers

Use ini_set():

ini_set('session.use_cookies', '0');

Or in your php.ini file:

session.use_cookies = 0
like image 180
Paige Ruten Avatar answered Sep 17 '22 14:09

Paige Ruten


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

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';
like image 34
lock Avatar answered Sep 17 '22 14:09

lock