Page 1 of 1

How do i set persistent session using PHPSESSID?

Posted: Wed Mar 28, 2007 3:33 am
by urnetmate
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


How do i set persistent session using PHPSESSID?

I have written following code:

Code: Select all

/**************START**************/
if(!isset($_COOKIE['PHPSESSID']))
{
	session_set_cookie_params(60*60*24*365);
	session_start();
	$tmp_sessionId = session_id();		
}
else
{	
	session_start();
	$tmp_sessionId = $_COOKIE['PHPSESSID'];	
}
/***************END***************/
In above code I am setting the PHPSESSID expiry limit for 1 year. But if i again come and access the same page the else part gets executed and on session_start() the PHPSESSID expiry date again replaces according to php.ini settings.
if i comment session_start() in else part everything works fine, but i can't set or access session data.

Plz help me to solve this.
Thanks in advance


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Mar 28, 2007 6:50 am
by blackbeard
Look up $_SESSION

Posted: Wed Mar 28, 2007 10:03 am
by s.dot
Look for $_COOKIE[session_id()].

I doubt you'll get a session to last a year... even when it's configured in the php.ini file for your session's lifetime to last that long. But who knows, you may. I've never heard of anyone trying it.

Posted: Wed Mar 28, 2007 3:21 pm
by RobertGonzalez
Typical session lifetime is 24 minutes with no activity.

Changing that to a year could really but a crimp on your system and you should either reconsider that set up or move to DB based sessions instead.