Jump to content

[SOLVED] PHP-4 alternative to deleting old-sessions by I.D.?


Goldeneye

Recommended Posts

I'm using PHP-4.4.* and also using session_regenerate_id() in one of my scripts which is called periodically. I'm looking for a way to delete the old-sessions. I was going to use the "Delete old Session-Data" parameter in session_regenerate_id() but that's only supported in PHP-5.1+. Is there a way to delete old sessions by their I.D.'s? Or perhaps reading the session-files and loading them all into an array and then truncating that array for duplicates? Any help is appreciated.

 

Thank you.

try

<?php

//  get session id of an existing session
$sid = $_GET['sid'];

//  start the old session to retrieve $_SESSION data
session_id($sid);
session_start();

//  start a new session; this copies the $_SESSION data over
session_regenerate_id();

//  hang on to the new session id
$sid = session_id();

//  close the old and new sessions
session_write_close();

//  re-open the new session
session_id($sid);
session_start();

/* main code here */

?>

I tried the code as is but what I got was:

Warning: session_start() [function.session-start]: The session id contains illegal characters, valid characters are a-z, A-Z, 0-9 and '-,' in E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php on line 13

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php:13) in E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php on line 13

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php:13) in E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php on line 13

Warning: session_regenerate_id() [function.session-regenerate-id]: Cannot regenerate session id - headers already sent in E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php on line 16

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php:13) in E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php on line 26

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php:13) in E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php on line 26

Warning: Cannot modify header information - headers already sent by (output started at E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php:13) in E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php on line 209

Warning: Cannot modify header information - headers already sent by (output started at E:\Web\devopment\localhost\htdocs\si\php4_v2\globals.php:13) in E:\Web\devopment\localhost\htdocs\si\php4_v2\class.users.php on line 49

 

My session-IDs allegedly contain illegal characters. I'm not quite sure for the reason of this. The only thing I can think of is that I do not append the session-ID to the URL.

So session_regenerate_id() only invalidates the old session - it doesn't delete it. I understand this now. Thanks for clarifying this for me, phpSensei! Session always gave me quite a bit of trouble. Hopefully I don't run into anymore misunderstandings.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.