timing out a session

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
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

timing out a session

Post by Luke »

This function will time out exactly 2 hours after the page is first called I believe. How would I fix this to make it reset the two hours every time the page loads? (my brain is kinda on vacation right now)

Code: Select all

function set_time_out(){
		// Set time start
                $this->duration = 60*60 * 2;
		$this->time_start = $this->get_var('time_start');
		if(!empty($this->time_start)){
			$this->time_out = ($this->time_start + $this->duration);
			if(time() > $this->time_out) $this->destroy();
		}
		else{
			$this->time_start = time();
			$this->set_var('time_start', $this->time_start);
		}
	}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: timing out a session

Post by Luke »

Code: Select all

function set_time_out(){
		// Set time start
                $this->duration = 60*60 * 2;
		$this->time_start = $this->get_var('time_start');
		if(!empty($this->time_start)){
			$this->time_out = ($this->time_start + $this->duration);
			if(time() > $this->time_out) $this->destroy();
		}
		else{
			$this->time_start = time();
			$this->set_var('time_start', $this->time_start);
		}
		$this->set_var('time_start', time()); // <-- I just needed to add this line I figured it out thanks!
	}
Post Reply