TRY IT
<?php session_name("first"); session_start(); echo session_status(); session_destroy(); echo session_status(); session_name("second"); session_start(); echo session_status(); session_destroy(); echo session_status(); ?>
I tested it on xampp and it returns 2121, which means that the session is active, does not exist, the session is active, does not exist.
I placed session_name () before session_start (), because setting the name, like you, did not take effect after the session is already running. I was looking for it, and it should do something with the php.ini file, where session.auto_start is set to "true".
An explanation and discussion on this topic can be found here: http://php.net/manual/en/function.session-name.php - check comments.
Edition:
After re-viewing your edit, you basically do not create two sessions, but only one, and it starts with the random name "first" or "second". You can destroy the session, but the cookie will remain. I checked your xampp code and it does just that. First, php starts one session and saves a cookie with a temporary value of βsessionβ, after reloading the page it will load one of the two parameters again, but this time it will change the existing cookie time to βN / Aβ. You should find a solution to clear cookies in your domain after loading the page as follows:
<?php $session_name = rand(0,1) ? 'first' : 'second'; session_name($session_name); session_start(); deleteCookies($session_name); function deleteCookies($skip_this_one) { if (isset($_SERVER['HTTP_COOKIE'])) { $cookies = explode(';', $_SERVER['HTTP_COOKIE']); foreach($cookies as $cookie) { $parts = explode('=', $cookie); $name = trim($parts[0]); if ($name == $skip_this_one) {
This will delete all previous cookies and save the current session.
This solution is rewritten here: how to delete all cookies of my website in php
Hope this helps :)