tags:

views:

48

answers:

3

Ok so my main page has a session. I am using the session id to query the database.

Now when I post to a page I have session_start() at the top but when I echo the session_id() on the main page and on the page that was posted to they are 2 different values. Why is it changing the session_id()?

Is there a way to make it keep the original value?

EDIT:

index.php

<?php
session_start();
echo session_id(); 
?>
<form method="post" action="post.php">
<input type="text" name="some_field" />
</form>

post.php

session_start();
echo session_id();

The session_id in index.php is different from the one in post.php!

+1  A: 

are you sure your browser is accepting cookies like it should be ? To make sure you try in a different browser then your usual one

RageZ
yes my browser is accepting cookies. i also tried in another browser just to confirm and it does the same thing.
ngreenwood6
can you turn the error_reporting to E_ALL with following code `error_reporting(E_ALL);`, session_start might output some *warning*.
RageZ
I figured out kinda whats going on by looking at my cookies. There are 2 cookies one is PHPSESSID and the other is SESSf9a1dfbab4f36b89eaf8b74ce485ad62. The one on the index.php page outputs the SESSf9a1dfbab4f36b89eaf8b74ce485ad62 and the one on the post.php page outputs the PHPSESSID one. Any ideas on how to fix this? I need this one SESSf9a1dfbab4f36b89eaf8b74ce485ad62.
ngreenwood6
would you be able to clear those cookies and see what happens ?
RageZ
A: 

sounds like you are some how changing the name of the session, or you need to change the name of teh session.

why not output the name of teh session as well as its ID

eg:

echo session_name();
echo "<br/>";
echo session_id();

if some hwere your session name is being changed, you will have to use that name all the time. PHPSESSID is teh default name for the session. SESSf9a1dfbab4f36b89eaf8b74ce485ad62 sounds like something you have changed it too..

you could also check session_id() to see what value is being stiored in the name. you can explicitly set all of tehse values, and if something in your code is doing so, you had better track it down.

(I am asuming that there is more to your code than what you put up)

Bingy
A: 

http://www.php.net/manual/en/function.session-id.php says:

Note: When using session cookies, specifying an id for session_id() will always send a new cookie when session_start() is called, regardless if the current session id is identical to the one being set.

and

If id is specified, it will replace the current session id. session_id() needs to be called before session_start() for that purpose. Depending on the session handler, not all characters are allowed within the session id.

powtac