Solved

PHP5: why session id does not change after session_destroy() is called?

Posted on 2014-10-08
1
334 Views
Last Modified: 2014-10-08
Hello Experts,

Why is my session id the same after calling session_destroy()?

Please see code below:

session_name('TESTSession');
session_start();

echo 'session id: '.session_id().'<br>';

if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 60)) {
	session_unset();     // unset $_SESSION variable for the run-time
	session_destroy();   // destroy session data in storage
}
		
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
echo 'session last activity: '. $_SESSION['LAST_ACTIVITY'] . '<br>';			

Open in new window

0
Comment
Question by:epifanio67
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
The session id is stored client side so isn't destroyed even though all the session values have been
To get a new id use session_regenerate_id()

<?php

session_name('TESTSession');
session_start();

echo 'session id: '.session_id().'<br>';

if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 60)) {
	session_destroy();   // destroy session data in storage
	session_unset();     // unset $_SESSION variable for the run-time
	session_regenerate_id(true);
}

		
$_SESSION['LAST_ACTIVITY'] = time(); // update last activity time stamp
echo 'session last activity: '. $_SESSION['LAST_ACTIVITY'] . '<br>';	

Open in new window

0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now