Jump to content

Losing SOME session variables after a header redirect


chersull_99

Recommended Posts

I have four session variables, two I am valueing using $_POST elements from a previous page's form, the other two I am valueing using items retrieved from a database.  Here is the code -

----------------------------------------------------

<?php session_start();

$_SESSION['UserLastName'] = strtolower(trim($_POST['txtLastName']));

$_SESSION['BadgeID'] = trim($_POST['txtBadgeID']);

 

//get list for supervisor drop down

$q1 = sprintf("select * from emps where emp_last = '".$_SESSION['UserLastName']."' and emp_badge = '".$_SESSION['BadgeID']."'");

 

$rs_emp_info = hitMSSQL($q1,"intra_sql","employees","xxxx","xxxx",1);

 

$_SESSION['SSN'] = $rs_emp_info->fields("emp_ssn");

$_SESSION['CostCenter'] = $rs_emp_info->fields("emp_costcenter");

 

if ($_POST['rdoAction'] == 0)

{

    header("Location: http://webapps/injury/empForm.php");

}

?>

----------------------------

 

When I get to the next page, empForm.php, the Last name and badge ID session vars are populated but the SSN and Cost Center session vars are not.  I have tried several things including putting an exit(); after my header statement and first putting the database items into plain old $vars and then trying to populate the session vars with the value of the regular $vars, but nothing seems to work.  I have a session_start() at the top of all of my scripts. 

 

Any idea why I am losing these values? (and why this box that I am typing into on this site is bouncing around so badly that I can't see what I am typing here???) :wtf:

Link to comment
Share on other sites

Well here is ONE way to get the data to my empForm.php screen, but it doesn't solve my original question - and it seems really hokey.  Basically if the action the screen is supposed to redirect to the empForm.php screen, I have it build a form and submit it, placing my SSN and Cost Center values as hidden form fields.  ewwww...

 

-------------------------------------------------

if ($_POST['rdoAction'] == 0)

{?>

      <form name="frmGoToEmpForm" ID="frmGoToEmpForm" method="post" action="empForm.php">

                <input type="hidden" id="hdnSSN" name="hdnSSN" value="<?php print $rs_emp_info->fields("emp_ssn");?>" />

                <input type="hidden" id="hdnCostCenter" name="hdnCostCenter" value="<?php print $rs_emp_info->fields("emp_costcenter");?>" />

      </form>

        <script language="javascript">frmGoToEmpForm.submit();</script>

            <?php

}?>

Link to comment
Share on other sites

If I echo the SSN and Cost Center session variables before redirecting, the values are there.  If I echo them on the page I'm redirecting to, they are not.

 

The Last Name and Badge ID session variables are populated before and after redirection.  It only seems that the SSN and Cost Center session variables are losing their value upon redirection.   

Link to comment
Share on other sites

Sorry, that didn't work either. 

 

Note the change in the subject line.  I discovered that if I populate my disappearing session vars from MYSQL rather than MSSQL, they stick after the redirect.  Curiouser and curiouser.

 

The SSN and Cost Center session vars that are coming from my MSSQL database are still blank on the http://webapps/injury/empForm.php page after applying the change you suggested.  The entire application begins on http://webapps/injury/default.php, where the Last Name and Badge ID# are entered.  The user is also asked if he needs to start a new report or check the status of an existing report.  This is there the rdoAction is coming from. 

 

The form on default.php is submitted to http://webapps/injury/mainRedirect.php, which is where the code in question appears.  This page takes the Last Name and Badge ID values posted there and puts them into session vars.  It then queries the MS SQL database and puts the SSN and Cost Center into two other session vars, which are getting lost on the redirect.  Just for grins I added a random query to a MYSQL database and stored one of those values into a session var and THIS session var sticks when I redirect to empForm.php. 

 

So it seems clear now that the problem is isolated to session vars populated using values from an MS SQL query.  Any ideas, PHP-ers???

Link to comment
Share on other sites

I am restarting this thread under a new subject line b/c issues I discovered related to this are no longer accurately reflected in the "Losing SOME session variables..." subject.  Please look for the new question - "Why do session vars loaded from a MSSQL query drop, while those loaded from a MYSQL query stick?" Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.