Hi
when i submit a form the session id changes in a page (and stick the same in single tab for other pages) but it is different in different tabs. how to fix that ?
thanks in advance
Hi
when i submit a form the session id changes in a page (and stick the same in single tab for other pages) but it is different in different tabs. how to fix that ?
thanks in advance
@lilly_adam
when i submit a form the session id changes in a page (and stick the same in single tab for other pages) but it is different in different tabs. how to fix that ?
Can you post the code so we can see what you are doing and try to assisted you?
//pageone.php
<?php
session_start();
echo session_id();
echo "<form action='pagetwo.php' method='post'>
<input type='test' name='username'/>
<input type='password' name='password'/>
<input type='submit' name='submitbtn'/>
</form>
";
?>
// pagetwo.php
<?php
session_start();
echo session_id();
?>
when i back to visit pagetwo.php or pageone.php from different tab it gives me different session id
@lilly_adam
when i back to visit pagetwo.php or pageone.php from different tab it gives me different session id
I'm bit confused. I thought you had session_id
part of a form that you submit that gave you a different session_id()
.
You can't echo a session_id()
function like that and expect to get the same id.
Let me explain how this works:
For pageone
:
You have to start your session in pageone.php
and assign a value to a session variable
.
session_start();
$_SESSION['id'] = "echoid";
For pagetwo
:
You need to use variable
defined in previous page in order to appear in the current page(pagetwo.php
).
session_start();
echo $_SESSION['echoid'];
I hope that make sense. I explain it very clearly.
Hi lilly_adam,
I read in a recent Daniweb post (I can't remember which one) that if your PHP configuration has session.auto_start enabled, whenever you use session_start() manually it overwrites the existing session with a new one. This feature is disabled by default but you may want to check your configuration, just in case.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.