Jump to content

[SOLVED] Need some guidence with sessions and redirects


jim.davidson

Recommended Posts

I'm teaching myself php, and I'm stuck. I have a two part form, each part on a seperate page. I want to send info from page one to page two. Thought ok, I use session variables. The problem is that they don't get sent to the second page. All works fine on my local testing server, but when I go live session varables don't show. Has this something to do with header? Is there another way to get to the second page?

 

Any help would be welcomed>

 

 

Here's part of the code

 

After user submits first form I load if to session variables in step one

 

$_SESSION['number_divers'] = $number_drivers;

$_SESSION['number_vehicles'] = $number_vehicles;

$_SESSION['current_insurance'] = $current_insurance;

$_SESSION['current_company'] = $current_company;

$_SESSION['refferal'] = $refferal;

 

// go to step two

header('Location: http://myinsurance.com/my_auto_quotes_2.php');

}

?>

 

Step Two

 

<?php

if (!isset($_SESSION)) {

session_start();

}

echo $_SESSION['number_divers'];

echo $_SESSION['number_divers'];

echo $_SESSION['number_vehicles'];

echo $_SESSION['current_insurance'];

echo $_SESSION['current_company'];

echo $_SESSION['refferal'];

?>

 

I dont' see anything

 

Link to comment
Share on other sites

I put session_start(); on both pages, did'nt make a difference.  I stil don't see anything from the echo's.

 

I need to know what's in $_SESSION['number_divers'] in order to format the second form i.e. I only want detailed driver info depending on the number of drivers.  So if there's two I have driver 1 input detail section and driver 2 input detail sections. If there would be three or four I'd add more.

 

This all works fine when I'm testing on my localhost, but when I upload and try "live" the session variables don't go over.  The only difference in the code is this

 

When local I use this:

  header('Location: http://localhost/my_auto_quotes_2.php');

 

When I'm live I use this:

  header('Location: http://myinsurance.com/my_auto_quotes_2.php');

Link to comment
Share on other sites

you'll need to amend your $_SESSION variable assignments on the form submission page:

 

$_SESSION['number_divers'] = $_POST['number_drivers'];
$_SESSION['number_vehicles'] = $_POST['number_vehicles'];
$_SESSION['current_insurance'] = $_POST['current_insurance'];
$_SESSION['current_company'] = $_POST['current_company'];
$_SESSION['refferal'] = $_POST['refferal']; 

 

if register_globals isn't on (and it usually isn't), those local variables won't be populated from the form.

Link to comment
Share on other sites

Here's the code from part one.  Depending whether or not I'm testing or live is which line gets commented out on the goto step two.

 

<?php  session_start();

$number_drivers = '';

$number_vehicles = '';

$current_insurance = '';

$current_company = '';

$refferal = '';

if (array_key_exists('step_two', $_POST)) {

// continue button clicked

  // remove escape characters from POST array

  if (get_magic_quotes_gpc()) {

    function stripslashes_deep($value) {

      $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);

      return $value;

    }

    $_POST = array_map('stripslashes_deep', $_POST);

  } // end magic quotes

  // get input

  $number_drivers = trim($_POST['number_drivers']);

  $number_vehicles = trim($_POST['number_vehicles']);

  $current_insurance = trim($_POST['current_insurance']);

  $current_company = trim($_POST['current_company']);

  $refferal = trim($_POST['refferal']);

  $_SESSION['number_divers'] = $number_drivers; 

  $_SESSION['number_vehicles'] = $number_vehicles; 

  $_SESSION['current_insurance'] = $current_insurance; 

  $_SESSION['current_company'] = $current_company; 

  $_SESSION['refferal'] = $refferal; 

  // go to step two

 

// header('Location: http://localhost/btracy_auto_quotes_2.php');

header('Location: http://bobtracyinsurance.com/btracy_auto_quotes_2.php');

}

?>

 

This is step two

I put these echos right at the beginning to check the input from step one. When I'm running on the local host header('Location: http://localhost/btracy_auto_quotes_2.php') I see info and everything works just fine. 

If I'm running live header('Location: http://bobtracyinsurance.com/btracy_auto_quotes_2.php') I see nothing and everything defaults to one driver, even though I said 3 on step one.

 

<?php

session_start();

echo $_SESSION['number_divers'];

echo  $_SESSION['number_divers']; 

echo  $_SESSION['number_vehicles']; 

echo  $_SESSION['current_insurance']; 

echo  $_SESSION['current_company']; 

echo  $_SESSION['refferal']; 

Link to comment
Share on other sites

you'll need to amend your $_SESSION variable assignments on the form submission page:

 

$_SESSION['number_divers'] = $_POST['number_drivers'];
$_SESSION['number_vehicles'] = $_POST['number_vehicles'];
$_SESSION['current_insurance'] = $_POST['current_insurance'];
$_SESSION['current_company'] = $_POST['current_company'];
$_SESSION['refferal'] = $_POST['refferal']; 

 

if register_globals isn't on (and it usually isn't), those local variables won't be populated from the form.

just recognized it.  this is your problem.  your declaring variables but the values are not populated as soon as you enter info in the boxes.  you need to submit the form (to the same page in this case) and set your $_SESSION variables equal to the $_POST values.

Link to comment
Share on other sites

No that wasn't it still no go. I'm going to add the entire code I hope someone will take a few minutes a tell me what I'm doing wrong.  It's probably a little sloppy, but I trying.

 

I really need to find what I'm doing wrong it's driving me nuts.

 

Thanks in advance to all for the help

 

Here the code for page one

 

<?php  session_start();

$number_drivers = '';

$number_vehicles = '';

$current_insurance = '';

$current_company = '';

$refferal = '';

// read somewhere to set session variables to nothing at beginning

 $_SESSION['number_divers'] = $number_drivers;  

 $_SESSION['number_vehicles'] = $number_vehicles;  

 $_SESSION['current_insurance'] = $current_insurance;  

 $_SESSION['current_company'] = $current_company;  

 $_SESSION['refferal'] = $refferal;  

 

if (array_key_exists('step_two', $_POST)) {

// continue to step two button clicked

 // remove escape characters from POST array

 if (get_magic_quotes_gpc()) {

   function stripslashes_deep($value) {

     $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);

     return $value;

   }

   $_POST = array_map('stripslashes_deep', $_POST);

 } // end magic quotes

 // get input and store to session variables

 

 $_SESSION['number_divers'] = $_POST['number_drivers'];  

 $_SESSION['number_vehicles'] = $_POST['number_vehicles'];  

 $_SESSION['current_insurance'] = $_POST['current_insurance'];  

 $_SESSION['current_company'] = $_POST['current_company'];  

 $_SESSION['refferal'] = $_POST['refferal'];

 // go to step two

session_write_close();  

// depending on wheather I'm testing or live as to which header I use

// header('Location: http://localhost/btracy_auto_quotes_2.php');

header('Location: http://bobtracyinsurance.com/btracy_auto_quotes_2.php');

exit;

}

?>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<meta name="description" content="Free auto quotes at Bob Tracy Insurance serving Beaver County's Insurance needs">

<meta name="keywords" content="bob tracy insurance,insurance,beaver pa 15009,Beaver PA,15009,tracy,Bob Tracy,personal attention,quotes,free auto insurance quote,free quotes,car insurance">

 

<title>Get free auto insurance quotes at Bob Tracy Insurance</title>

<link href="CssFiles/tracy.css" rel="stylesheet" type="text/css" />

<style type="text/css">

<!--

#auto1_main {position:absolute;

width:713px;

height:399px;

z-index:1;

left: 175px;

top: 20px;

}

.style6 {font-size: 12px}

.left_info {font-size: small}

.style1 {font-size: 14px}

#menu {

position:absolute;

width:143px;

height:640px;

z-index:1;

left: 3px;

top: 1px;

background-color: #547E29;

}

#tracy_slide { position:absolute;

width:140px;

height:140px;

z-index:5;

left: 713px;

top: 5px;

}

.style7 {font-size: x-small}

-->

</style>

</head>

 

<body>

<div id="auto1_main">

 <table width="700" border="0" align="center" cellpadding="0">

   <tr>

     <td><form id="auto_one" name="auto_one" method="post" action="<?php $_SERVER['PHP_SELF'];?>">

       <table width="680" border="0" align="center" cellpadding="0">

         <tr>

           <td colspan="3"><div align="center">

             <h3>Auto Quote Step 1 of 2 </h3>

           </div></td>

           </tr>

         <tr>

           <td width="402"><h3>About You </h3></td>

           <td width="21"> </td>

           <td width="249"> </td>

         </tr>

         <tr>

           <td height="15"> </td>

           <td> </td>

           <td> </td>

         </tr>

         <tr>

           <td class="style1">How many drivers are in your household? </td>

           <td> </td>

           <td><select name="number_drivers" id="number_drivers">

             <option value="" selected="selected">Please Select</option>

             <option value="1">One</option>

             <option value="2">Two</option>

             <option value="3">Three</option>

             <option value="4">Four</option>

             <option value="5">Five</option>

                       </select>

             <span class="left_info">*</span></td>

         </tr>

         <tr>

           <td> <span class="style6">  * Include yourself, your spouse, anyone of driving age in your household, and all other drivers of your vehicles.</span> </td>

           <td> </td>

           <td> </td>

         </tr>

         <tr>

           <td> </td>

           <td> </td>

           <td> </td>

         </tr>

         <tr>

           <td class="style1">How many vehicles are you insuring? </td>

           <td> </td>

           <td><select name="number_vehicles" id="number_vehicles">

             <option value="0" selected="selected">Please Select</option>

             <option value="1">One</option>

             <option value="2">Two</option>

             <option value="3">Three</option>

             <option value="4">Four</option>

             <option value="5">Five</option>

           </select>

             <span class="left_info">              *</span></td>

         </tr>

         <tr>

           <td class="left_info">   * If zero, the remaining questions are optional </td>

           <td> </td>

           <td> </td>

         </tr>

         <tr>

           <td> </td>

           <td> </td>

           <td> </td>

         </tr>

         <tr>

           <td class="style1">Do you currently have auto insurance? </td>

           <td> </td>

           <td><select name="current_insurance" id="current_insurance">

             <option selected="selected">Please Select</option>

             <option value="Yes">Yes</option>

             <option value="Yes, I am on my parents policy">Yes, I am on my parents policy</option>

             <option value="No">No</option>

             <option value="No, my insurance ran out">No, my insurance ran out</option>

             <option value="No, my car broke down">No, my car broke down</option>

             <option value="No, I haven't owned a car recently">No, I haven't owned a car recently</option>

             <option value="No, I've never owned a car before">No, I've never owned a car before</option>

             <option value="No, I have a company car">No, I have a company car</option>

           </select>

             <span class="left_info">*</span></td>

         </tr>

         <tr>

           <td> </td>

           <td> </td>

           <td> </td>

         </tr>

         <tr>

           <td class="style1">What

insurance company are you currently insured with, or previously insured

with?</td>

           <td> </td>

           <td><select name="current_company" id="current_company">

             <option value=""> -- Please Select -- </option>

 <option value="None">None</option>

         

           <option value="AIG" >AIG</option>

         

           <option value="Allstate" >Allstate</option>

         

           <option value="Amica" >Amica</option>

         

           <option value="Chubb" >Chubb</option>

         

           <option value="Country-Wide Ins Co" >Country-Wide Ins Co</option>

         

           <option value="Dairyland" >Dairyland</option>

         

           <option value="Deerbrook" >Deerbrook</option>

         

           <option value="Drive Insurance" >Drive Insurance</option>

         

           <option value="Encompass (CNA)" >Encompass (CNA)</option>

         

           <option value="Erie Insurance" >Erie Insurance</option>

         

           <option value="Farmers" >Farmers</option>

         

           <option value="Firemans Fund" >Firemans Fund</option>

         

           <option value="GEICO" >GEICO</option>

         

           <option value="GMAC (Integon)" >GMAC (Integon)</option>

         

           <option value="Great American" >Great American</option>

         

           <option value="Hartford" >Hartford</option>

         

           <option value="Insurequest" >Insurequest</option>

         

           <option value="Liberty Mutual" >Liberty Mutual</option>

         

           <option value="Mercury Casualty" >Mercury Casualty</option>

         

           <option value="Metropolitan" >Metropolitan</option>

         

           <option value="Nationwide" >Nationwide</option>

         

           <option value="NY Auto Insurance Plan (NYAIP)" >NY Auto Insurance Plan (NYAIP)</option>

         

           <option value="NY Central Mutual" >NY Central Mutual</option>

         

           <option value="One Beacon (CGU)" >One Beacon (CGU)</option>

         

           <option value="Other Not-Listed Ins Company" >Other Not-Listed Ins Company</option>

         

           <option value="Progressive Insurance Company" >Progressive Insurance Company</option>

         

           <option value="Prudential" >Prudential</option>

         

           <option value="Royal Sun Alliance" >Royal Sun Alliance</option>

         

           <option value="Safeco" >Safeco</option>

         

           <option value="State Farm" >State Farm</option>

         

           <option value="Statewide Ins Co" >Statewide Ins Co</option>

         

           <option value="Travelers" >Travelers</option>

         

           <option value="US Capital Ins Co" >US Capital Ins Co</option>

         

           <option value="USAA" >USAA</option>

         

           <option value="Utica Mutual Ins Co" >Utica Mutual Ins Co</option>

         

           <option value="Windsor" >Windsor</option>

         

           <option value="NYSIF" >NYSIF</option>

           </select>

             <span class="left_info">*</span></td>

         </tr>

         <tr>

           <td> </td>

           <td> </td>

           <td> </td>

         </tr>

         <tr>

           <td class="style1">How did you hear about us? </td>

           <td> </td>

           <td><select name="refferal" id="refferal">

                       <option value=""> -- Please Select -- </option>

         

           <option value="Current Client" >Current Client</option>

         

           <option value="Referral of Friend" >Referral of Friend</option>

         

           <option value="Yellow Pages" >Yellow Pages</option>

         

           <option value="Former Bob Tracy Client" >Former Bob Tracy Client</option>

         

           <option value="Newspaper-Insert" >Newspaper-Insert</option>

         

           <option value="Direct Mailer" >Direct Mailer</option>

         

           <option value="Saw Our Office" >Saw Our Office</option>

         

           <option value="Radio" >Radio</option>

         

           <option value="Netquote -purchased lead" >Netquote -purchased lead</option>

         

           <option value="Billboard" >Billboard</option>

         

           <option value="Erie from another agent/state" >Erie from another agent/state</option>

         

           <option value="Car Dealership" >Car Dealership</option>

         

           <option value="Internet / Our Website" >Internet / Our Website</option>

           </select>

             *</td>

         </tr>

         <tr>

           <td> </td>

           <td> </td>

           <td> </td>

         </tr>

       </table>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

         <tr>

           <td><h3>Important Information</h3></td>

         </tr>

       </table>

 

       <table width="100%" border="1" cellpadding="5" cellspacing="0" bordercolor="#333333" class="content">

         <tr>

           <td align="center"><div align="left" class="left_info">Information Disclosure: To provide

               a quote, we will collect information from consumer reporting agencies,

               such as driving record and claims history reports. We will also

               review your credit report and use a credit-based insurance score

               based on information contained in that report. An insurance score

               uses information from your credit report to help predict how often

               you are likely to file claims and how expensive those claims will

               be. Typical items from a credit report that could affect a score

               include, but are not limited to, the following: payment history,

               length of reported credit history, number of loans and accounts

               with current payment status, and number of inquiries. The information

               used to develop the insurance score comes from one of the following

               consumer reporting agencies: Experian, TransUnion, or Equifax.

               Future reports may be used to update or renew your insurance.

             </div></td>

         </tr>

       </table>

 

 

 

       <table width="682" border="0" align="center" cellpadding="0" id="step_two">

 

         <tr>

           <td width="39"> </td>

           <td width="228"> </td>

           <td width="407"><input name="step_two" type="submit" id="step_two" value="Continue to Step Two" /></td>

         </tr>

         

</table>

     </form>

     </td>

   </tr>

 </table>

</div>

<p> </p>

 

<div id="menu">

 

 <p>

 <p> </p>

<p> </p>

   <script menumaker>document.write('<scr' + 'ipt src="images/mainmenu1.js">'+'</scr'+'ipt>');/*img src="images/mainmenu1.gif" moduleid="bob tracy (project)\mainmenu1_off.xws"*/</script>

 </p>

 

 <p>  </p>

 <table width="140" border="0" cellpadding="0">

   <tr>

     <th width="184" class="whitefont" scope="col"><div align="center" class="left_info"> Bob Tracy Insurance </div></th>

   </tr>

   <tr>

     <td class="whitefont"><div align="center" class="left_info"> 433 State Street</div></td>

   </tr>

   <tr>

     <td class="whitefont"><div align="center" class="left_info"> Beaver, PA  15009</div></td>

   </tr>

   <tr>

     <td class="whitefont"><div align="center" class="style1">

       <div align="center"></div>

     </div></td>

   </tr>

   <tr>

     <td class="whitefont"><div align="center" class="left_info"> (724) 728 - 1200</div></td>

   </tr>

   <tr>

     <td class="whitefont"> </td>

   </tr>

   <tr>

     <td class="whitefont"><div align="center">Monday thru Friday </div></td>

   </tr>

   <tr>

     <td class="whitefont"><div align="center">8:30 - 4:30 </div></td>

   </tr>

   <tr>

     <td class="left_info"><div align="center" class="whitefont style7">Evenings by appointment </div></td>

   </tr>

 </table>

 <p>  </p>

</div>

</body>

</html>

 

 

 

Link to comment
Share on other sites

Problem solved. I stumbled upon myself.

 

For the header I had this...

header('Location: http://bobtracyinsurance.com/btracy_auto_quotes_2.php');

 

What I should have had was this...

header('Location: http://www.bobtracyinsurance.com/btracy_auto_quotes_2.php');

 

Three little w's made the difference, session variables now work.

 

Thanks to all for their suggestions

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.