Forum Moderators: coopster

Message Too Old, No Replies

$_SESSION[cid] changes for no logical reason

The value changes in mid session in a reproducable but inexplicable way

         

matt1066

1:51 pm on May 5, 2006 (gmt 0)

10+ Year Member



Pretty basic stuff on the surface;

<?php
session_start()
$thisuser = $_SESSION['uid'];
$thiscustomer = $_SESSION['cid'];
session_write_close();
?>

I'm using print_r to print the array for debugging.

I have script "abc.php" which displays page that allows users to select filter criteria for a search. This call a script "def.php" that is just a frameset with sources of scripts "view.php" and "edit.php". Another that edits the records. Everything works as expected. "view.php" and "edit.php" call the session variables with the above code and grab relavent information. "view.php" has a link that's built for each record to feed it to the "edit.php" script, i.e.:

echo "<TD><A href=\"fileedit.php?fileid=" . $query_data[fileid] . "&thisjob=" . $jobid . "\" target=\"fileediter\">" . $query_data['fileident'] . "</A></TD>";

This works great. .... However ... way back in script "abc.php" there is a pulldown input;

<select name="cfilter">
<option value="0">Any</option>
<option value="1" selected>A Test Company</option>
<option value="2">City Stamp Works</option>
<option value="3">Unicorr Packaging Group</option>
<option value="4">Timbar</option>
</select>

When I click the above link in "view.php" the value of $_SESSION['cid'] is changed to whatever the current value of the $cfilter from the above pulldown in "abc.php". All other $_SESSION vars stay the same like they should. Between all 4 scripts the only time a session is open is exactly what I have at the beginning of this postand they are at the top of each script before any whitespace.

Reproducable but inexplicable.

eelixduppy

4:42 pm on May 5, 2006 (gmt 0)



Welcome to WebmasterWorld!

It seems that the session variable is being reset at some point within your code. This may be the problem: Each of your pages have


<?php
session_start()
$thisuser = $_SESSION['uid'];
$thiscustomer = $_SESSION['cid'];
session_write_close();
?>

this at the beginning. Once the session variables are set, then you only need to type


session_start();

at the beginning of the page to retreive those variables. Instead, you are resetting those variables to potentially different values.

Hope this helps!

eelix

matt1066

6:12 pm on May 5, 2006 (gmt 0)

10+ Year Member



OK. I should have mentioned that the session_write_close() was a later addition attempting to control the behavior. The docs say that function closes the $_SESSION to writing. Sounded like that would prevent any odd misinterpretations of code setting the values.

When you say "set by accident" what do you mean here?

I would think there would have to be some sort of ;

session_start()
$_SESSION['cid'] = 5;

I get a little quesy when I think that a variable can just "take a value" at random whether it's a session variable or any other. Unless there is some other method/function/process that writes to session variables, there are no other lines that even reference the session other than what I've shown. The login script is the only one that ever sets the session variable. Every other script has only those first three lines. I'm still absolutely puzzled as to why it would happen when that link is clicked. And, why would it consistantly pick up the value of $cfilter?

coopster

2:52 pm on May 8, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Find out where this particular $_SESSION index's value is being setannd wherever you are setting the value, echo it to the browser. Start back-tracking from there.

matt1066

3:40 pm on May 8, 2006 (gmt 0)

10+ Year Member



I'll try it but I'm not optimistic. The session variables are set when the user logs in via Auth401.php. It's the only time the session variables are set and the only time that script is called. There's two more things that really make me wonder what's going on. First, I can see that the value changes when a link is clicked that runs the script fileedit.php. The script that builds the page with the link has a print_r() and I can see that the value of the session variables is set correctly when the page is built. The session variables are used in lines 3 and 4 of the fileedit.php script. There's not a lot of code under the bridge to miss something as obvious as "$_SESSION['cid'] = $cfilter;" Second, I have duplicated the entire site. Only I use $_SESSION['custo']. It works perfectly predicatably. There are other posting on this site that talk about inexplicable behaviors of $_SESSION['cid'] specifically with no resolutions.

Thanks for all the help folks.