Solved

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

Posted on 2014-10-08
1
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 500 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

617 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