0

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

3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by Zagga
0

@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?

0
//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

Edited by diafol: fixed code tags

0

@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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.