Reputation: 2241
I am using the session_name to rename my session to lets says 'xxx'. Using this I am also able to start a session using session_start. I also able see the cookie being set in my browser.
//TO SET session
session_name('xxx');
session_start();
But the problem is that I am not able to retrieve the session id using the session_id call in an another script.
session_name('xxx');
$id = session_id();
echo $id // This is showing empty
var_dump($_COOKIE) // This is showing the cookie xxx with the session id
if(!empty($id))
{
//If he is already logged in, lets get his details
session_start();
}
I know that I can go ahead and read the cookie to see if the session is set. But I was just curious to know why this is not working. Isn't the session_id function retrieve my session id after setting the session_name ?
We know the that session_start is going to open my existing session but on the other hand if at all there isn't session then it will start a new one. I don't want start a new session if it is not already started.
What am I doing wrong here?
Upvotes: 0
Views: 3137
Reputation: 522042
There will be no session_id
before you start the session with session_start
.
session_name
just sets the cookie/URL param name, it does not start a session.
And yes, you need to start()
the session on every single page you want to use it.
Upvotes: 2