Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-10-08
1
Medium Priority
?
404 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 2000 total points
ID: 40369528
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

885 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