How do i set persistent session using PHPSESSID?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
urnetmate
Forum Commoner
Posts: 27
Joined: Wed Sep 27, 2006 1:09 am

How do i set persistent session using PHPSESSID?

Post 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]
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

Look up $_SESSION
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

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