473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PHPSESSID expires before my cookie

I have the following code:

$expireTime = 60*60*24*364; // 365 days
session_set_cookie_params($expireTime); // seconds
session_start();

My problem is, that my PHPSESSID expires before my cookie. I have then
added the fowlloing code:

$expireTime = 60*60*24*364; // 365 days
session_set_cookie_params($expireTime); // seconds
session_cache_limiter('private');
session_cache_expire(8760); // minutes
session_start();

Now my cookie expires after the browser closes instead of the 365 days!?

How do I get the same expiration on both my cookie and my PHPSESSID on
my server?

I am running with PHP5 on a FreeBSD server.
Jul 17 '05 #1
7 10543
> How do I get the same expiration on both my cookie and my PHPSESSID on
my server?


No one that knows anything about it? I have tried a few thing, but I
can't get it working.
Jul 17 '05 #2
On Sun, 01 May 2005 02:39:24 +0200, FamB wrote:

No one that knows anything about it? I have tried a few thing, but I
can't get it working.


OK. What are the few things that you tried? What exactly do you want?
You want your PHPSESSID cookie to survive closing the browser, thus in
effect establishing a permanent session.

You are using PHP5. PHP5 has a parameter called session.cookie_lifetime.
Here is an explanation taken from the INI file.

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0
By the way, session cannot live longer then your browser. Once you
close your browser, your session is closed. The session_start()
function will start a new session. HTTPD is a stateless protocol.
You cannot trick it into allowing you permanent connection. It would be
nice, but no way to do that.

--
Egoist: A person of low taste, more interested in themselves than in me.

Jul 17 '05 #3
Mladen Gogala wrote:
By the way, session cannot live longer then your browser. Once you
close your browser, your session is closed. The session_start()
function will start a new session. HTTPD is a stateless protocol.
You cannot trick it into allowing you permanent connection. It would be
nice, but no way to do that.


Um. As you say, HTTP is a stateless protocol. That means that as far as
the server is concerned, closing a browser window does absolutely
nothing! It all hinges on whether or not *your browser* will send the
session cookie back to the server again when reopened. This is easy!
Just set your cookie's expiry date to some date years in the future (It
is a session only cookie by default), and your browser will send it back
to the server next time it visits.

Cheers,
Nicholas Sherlock
Jul 17 '05 #4
> You are using PHP5. PHP5 has a parameter called session.cookie_lifetime.
Here is an explanation taken from the INI file.

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0


Okay, I thought it was something that could be set in the PHP code but I
have now changed the value in my php.ini and that seems to solve the
problem. Thanks.
Jul 17 '05 #5
> You are using PHP5. PHP5 has a parameter called session.cookie_lifetime.
Here is an explanation taken from the INI file.

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0


Okay, perhaps I am mixing sessions and cookies together because I can
not get it working as I want.

I have this code:

if($autologin == "on")
{
$expireTime = 60*60*24*364; // 365 days
session_set_cookie_params($expireTime); // seconds
}
else
{
$expireTime = 0; // when browser closes
session_set_cookie_params($expireTime); // seconds
}
session_start();

"autologin" is a checkbox, to let the user have a permanent session.

What I want is, to set the client cookie to either 365 days or to die
when the browser closes.
I would prefer if the server session (PHPSESSID) expired at the same
time as the client cookie, but if that is not possible, then it should
just be 365 days.
Right now I have set "session.cookie_lifetime = 31536000" in my php.ini
and then this above code.

Can anyone help - either to let me understand what I am missing or with
an example?
Jul 17 '05 #6
>> You are using PHP5. PHP5 has a parameter called session.cookie_lifetime.
Here is an explanation taken from the INI file.

; Lifetime in seconds of cookie or, if 0, until browser is restarted.
session.cookie_lifetime = 0


Okay, perhaps I am mixing sessions and cookies together because I can
not get it working as I want.

I have this code:

if($autologin == "on")
{
$expireTime = 60*60*24*364; // 365 days
session_set_cookie_params($expireTime); // seconds
}
else
{
$expireTime = 0; // when browser closes
session_set_cookie_params($expireTime); // seconds
}
session_start();

"autologin" is a checkbox, to let the user have a permanent session.

What I want is, to set the client cookie to either 365 days or to die
when the browser closes.
I would prefer if the server session (PHPSESSID) expired at the same
time as the client cookie, but if that is not possible, then it should
just be 365 days.
Right now I have set "session.cookie_lifetime = 31536000" in my php.ini
and then this above code.

Can anyone help - either to let me understand what I am missing or with
an example?


I still have my problems with this. I hope there to be a solution for
it? :-)
Jul 17 '05 #7
FamB wrote:
<snip>
I still have my problems with this. I hope there to be a solution for it? :-)


Probably, it might be your session gc setting that trashes your
session.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: JohnS | last post by:
Hi, When I initially start my browser (any of 'm) and point it to my PHP script the $PHPSESSID is always blank. On all subsequent hits or after a refresh the value for $PHPSESSID is fine... why...
2
by: O.B. | last post by:
Using PHP 4.3.4, I have a problem where some web pages appear and the links all have PHPSESSID=4094c333eb638b1e8c25632212079e05 attached to them. The HTML code itself does not have this text. ...
7
by: windandwaves | last post by:
Dear Gurus Is it correct that you do not have to pass the PHPSESSID in the header in order to keep a session going. What are the advantages/disadvantages of having the PHPSESSID in the header ...
3
by: techie | last post by:
I am using the following to delete the contents of a cookie Response.Cookies("maincookie").expires = DateAdd("d",-2,now) Response.redirect "login.asp" If i try to alert the value of the cookie...
1
by: Chad Richardson | last post by:
I have several users data elements that I want to maintain and persist. I've created a cookie with keys to do this, but having problems with it persisting. 1. Do you set the .Expires at the...
0
by: joseph conrad | last post by:
Hi, I tried to implement my own session handler in order to keep control on the process the drawback I foun it is not creating and storing in my cookie the PHPSESSID variable anymore. reading te...
1
by: Leszek | last post by:
Hi. How should I configure Apache2.2 with php5 so that PHPSESSID would be sent as a cookie ? Now I'm not getting any messages even if I set IE to ask about incoming cookies... So what is the...
1
by: zorro | last post by:
Greetings, I want users to select the duration time of their sessions. I'm able to do it by setting the PHPSESSID cookie duration. Is this reliable, or is it not recommended for some reason? ...
4
by: Mark | last post by:
It's my understanding that the code below will create a session cookie (RAM based cookie) that does not persist to a file, but exists in memory on the client's pc and will be deleted when the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.