Goldeneye Posted August 4, 2009 Share Posted August 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/168737-solved-php-4-alternative-to-deleting-old-sessions-by-id/ Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 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 */ ?> Link to comment https://forums.phpfreaks.com/topic/168737-solved-php-4-alternative-to-deleting-old-sessions-by-id/#findComment-890241 Share on other sites More sharing options...
Goldeneye Posted August 4, 2009 Author Share Posted August 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/168737-solved-php-4-alternative-to-deleting-old-sessions-by-id/#findComment-890263 Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 edit: one sec.. Link to comment https://forums.phpfreaks.com/topic/168737-solved-php-4-alternative-to-deleting-old-sessions-by-id/#findComment-890271 Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 You can just session_id();. If id is specified, it will replace the current session id. session_id(). Link to comment https://forums.phpfreaks.com/topic/168737-solved-php-4-alternative-to-deleting-old-sessions-by-id/#findComment-890274 Share on other sites More sharing options...
Goldeneye Posted August 4, 2009 Author Share Posted August 4, 2009 Alright, it doesn't give any errors anymore. Is this also supposed to delete the old session-files or does just simply renew the session-ID? Link to comment https://forums.phpfreaks.com/topic/168737-solved-php-4-alternative-to-deleting-old-sessions-by-id/#findComment-890283 Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 Alright, it doesn't give any errors anymore. Is this also supposed to delete the old session-files or does just simply renew the session-ID? You cannot delete cookies of off the clients computer... It will renew the session-ID Link to comment https://forums.phpfreaks.com/topic/168737-solved-php-4-alternative-to-deleting-old-sessions-by-id/#findComment-890290 Share on other sites More sharing options...
Goldeneye Posted August 4, 2009 Author Share Posted August 4, 2009 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. Link to comment https://forums.phpfreaks.com/topic/168737-solved-php-4-alternative-to-deleting-old-sessions-by-id/#findComment-890291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.