shadowspy1 Posted December 29, 2009 Share Posted December 29, 2009 I am having an issue in which, sometimes, mostly in Firefox, that a user needs to login twice for the actual php session data to work. IE8 usually works without issues, but I can't say 100% error free. Validating the User <?php session_start(); // Start Session include 'db.php'; // Convert variables $pilotid = $_POST['pilotid']; $password = $_POST['password']; $encryptpassword = md5($_POST['password']); if((!$_POST['pilotid']) || (!$_POST['password'])){ echo "Please enter ALL of the information! <br />"; exit(); } // check if the user info validates the db $sql = mysql_query("SELECT * FROM users WHERE pilotid='$pilotid' AND password='$encryptpassword'"); $login_check = mysql_num_rows($sql); if($login_check > 0){ while($row = mysql_fetch_array($sql)){ foreach( $row AS $key => $val ){ $$key = stripslashes( $val ); } if($row['admin'] == 'Y'){ // Register some session variables! session_register('pilotid'); session_register('admin'); $_SESSION['pilotid'] = $pilotid; $_SESSION['admin'] = 'true'; header("Location: crewroom.php"); } else if($row['admin'] == 'N'){ session_register('pilotid'); $_SESSION['pilotid'] = $pilotid; header("Location: crewroom.php"); } } }else{ echo "You could not be logged in! Either the username and password do not match or you are not registered!<br /> Please try again!<br />"; } mysql_close($connection); ?> The page where the session seems to work after only logging in twice. <?php session_start(); include "db.php"; $flight = $_GET['number']; $section = $_GET['section']; $pilotnum = $_GET['pilotnum']; echo $pilotid; ?> <?php if(isset($pilotid)){ ?> <center> <input type="submit" name="Submit" value="Submit Bid"> </center> <? } ?> The issue is that Submit Button doesn't always show up. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/186559-php-session-login-session-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 29, 2009 Share Posted December 29, 2009 You cannot just put a submit button/form element on a page unless it is inside of a valid form, though some forgiving browsers might ignore that error and allow it to function and submit back to the same page. Your code is also using session_register(), which was depreciated long ago (7 years ago in fact) and cannot actually be used at the same time that you use $_SESSION variables. Since you are using the correct $_SESSION variables, remove all the code using session_register(). Quote Link to comment https://forums.phpfreaks.com/topic/186559-php-session-login-session-error/#findComment-985465 Share on other sites More sharing options...
shadowspy1 Posted December 29, 2009 Author Share Posted December 29, 2009 Ok, I will do that with the session_register(). The submit button is in a valid form, I just didn't put all of the html code in the code snippet on here. Quote Link to comment https://forums.phpfreaks.com/topic/186559-php-session-login-session-error/#findComment-985483 Share on other sites More sharing options...
PFMaBiSmAd Posted December 29, 2009 Share Posted December 29, 2009 The submit button is in a valid form, I just didn't put all of the html code in the code snippet on here. Cannot really help you with your code when you do things like that and you don't mention that the code has been altered for the post. It just wastes everyone's time. Quote Link to comment https://forums.phpfreaks.com/topic/186559-php-session-login-session-error/#findComment-985492 Share on other sites More sharing options...
shadowspy1 Posted December 29, 2009 Author Share Posted December 29, 2009 Ok. Here's the whole code for that page, to clear up any misunderstandings. <?php session_start(); include "db.php"; $flight = $_GET['number']; $section = $_GET['section']; $pilotnum = $_GET['pilotnum']; echo $pilotid; ?> <!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> <link rel="stylesheet" type="text/css" href="anylinkmenu.css" /> <script type="text/javascript" src="menucontents.js"></script> <script type="text/javascript" src="anylinkmenu.js"> /*********************************************** * AnyLink JS Drop Down Menu v2.0- © Dynamic Drive DHTML code library (www.dynamicdrive.com) * This notice MUST stay intact for legal use * Visit Project Page at http://www.dynamicdrive.com/dynamicindex1/dropmenuindex.htm for full source code ***********************************************/ </script> <script type="text/javascript"> //anylinkmenu.init("menu_anchors_class") //Pass in the CSS class of anchor links (that contain a sub menu) anylinkmenu.init("menuanchorclass") </script> <meta http-equiv="keyword" content="eastjet, eastjet virtual, virual airline, fs2004, fs9, fsx, airplane, hobby, flight simulator, flight, airline" /> <title>EastJet Virtual-"A New Level of Excellence"</title> <style type="text/css"> td img { display: block; text-align: center; }.style1 { font-family: Tahoma; font-weight: bold; font-size: 11px; } .style2 { font-family: Tahoma; font-size: 12px; } .style5 { font-family: Tahoma; font-size: 12px; color: #FFFFFF; font-weight: bold; } a { font-family: Tahoma; font-size: 11px; } .style7 {font-family: Tahoma} body { background-color: #CCCCCC; } .style11 {font-family: Tahoma; font-size: 12px; color: #092A51; font-weight: bold; } .style12 {color: #092A51} .style13 {font-size: 11px} .navbar { font-size: 11px; color: #FFFFFF; font-weight: bold; font-family: Tahoma; } .navbar a:link{color:white;} .navbar a:visited{color:white;} .navbar a:active{color:white;} .newsbar { font-size: 11px; color: #082952; font-family: Tahoma; font-weight:bold; } .newsbar a:link{color:#082952;} .newsbar a:visited{color:#082952;} .newsbar a:active{color:#082952;} .newsbar a:hover{color:#C00;} .style16 {font-family: Tahoma; font-size: 11px; } .style17 { color: #092A51; font-weight: bold; font-size: 11px; font-family: Tahoma; } tr.board td{ border-bottom-style:solid; border-bottom-width:1px; border-bottom-color:#CCCCCC; } #menu ul{ margin: 0px; padding: 0 0 0 70px; } #menu ul li { margin: 0px; float: left; list-style: none; } #menu ul li a { display: block; text-decoration: none; padding: 0px 32px; background: inherit; color: #FFFFFF; font:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; } #menu ul li a:hover { color: #aeaeae; } .tableborder{ border-left-width: 1px; border-right-width: 1px; border-right-color: #092a51; border-left-color: #092a51; border-left-style:solid; border-right-style:solid; } .newheader { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-size: 12px; font-weight: bold; color: #082952; } body{ font-family: Helvetica,Arial,sans-serif; margin: 0px 0px 0px 0px; font-size: 10px; } a.link1:link, a.link1:visited{ color:#ffffff; text-decoration:none; } a.link1:hover{ color:#95ddf9; } a:link { color: #082952; text-decoration: none; } a:hover { color: #C00; text-decoration: none; } a:visited { color: #082952; text-decoration: none; } a:active { text-decoration: none; } .badgename{ font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:16px; font-style:normal; color:#082952; } .hiredate{ font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px; font-style:normal; color:#082952; } .pilotid{ font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px; font-style:normal; color:#082952; } .rank{ font-family:Arial, Helvetica, sans-serif; font-weight:bold; font-size:12px; font-style:normal; color:#082952; } </style> </head> <body> <table width="800" border="1" bordercolor="#000000" rules="rows" align="center" style="border-collapse:collapse" cellpadding="0"> <tr> <td valign="top"><img src="banner.jpg" /></td> </tr> <tr background="bottombg.jpg"> <td height="23" background="bottombg.jpg" id="menu"> <ul> <li><a href="http://www.eastjetvirtual.com" class="link1">Home</a></li> <li><a href="http://eastjetvirtual.com/join.php" class="link1">Join</a></li> <li><a href="http://www.eastjetvirtual.com" class="menuanchorclass link1" rel="anylinkmenu1">Hubs</a></li> <li><a href="http://www.eastjetvirtual.com/flightops.php" class="menuanchorclass link1" rel="anylinkmenu2">Flight Ops</a></li> <li><a href="http://www.eastjetvirtual.com/forums" class="link1">Forums</a></li> <li><a href="http://www.eastjetvirtual.com/contact.php" class="link1">Contact Us</a></li> </ul></td> </tr> <tr> <td valign="top" bgcolor="#FFFFFF" class="style1" align="center" height="400"> <?php if ($section == ''){ ?> <form name="flightbid" method="post" action="../flightbid.php?section=flights"> <table width="430" border="0" align="center"> <tr> <td colspan="2"><img src="routemap.png" width="430" /> </td> </tr> <tr> <td width="120" class="style1" align="left">Aircraft</td> <td align="left"> <select name="equip" size="1"> <option value="%" selected>All Aircraft</option> <option value="B73W">Boeing 737-700</option> </select> </td> </tr> <tr> <td width="120" class="style1" align="left">Flight Type</td> <td align="left"> <select name="flighttype" size="1"> <option value="%" selected>All Flights</option> <option value="sked">Scheduled</option> <option value="charter">Charter</option> </select> </td> </tr> <tr> <td width="120" class="style1" align="left">Departure</td> <td align="left"> <select name="depart" size="1"> <option value ="%" selected="selected">All Airports</option> <option value="KBOS">Boston</option> <option value="KMDW">Chicago</option> <option value="KCVG">Cincinnati</option> <option value="KIND">Indianapolis</option> <option value="KLAX">Los Angeles</option> <option value="KSFO">San Francisco</option> <option value="KTPA">Tampa</option> </select> </td> </tr> <tr> <td width="120" class="style1" align="left">Arrival</td> <td align="left"> <select name="arrive" size="1"> <option value ="%" selected="selected">All Airports</option> <option value="KBOS">Boston</option> <option value="KMDW">Chicago</option> <option value="KCVG">Cincinnati</option> <option value="KIND">Indianapolis</option> <option value="KLAX">Los Angeles</option> <option value="KSFO">San Francisco</option> <option value="KTPA">Tampa</option> </select> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="Submit" value="Submit" /> </td> </tr> </table> </form> <br /> <table width="430" border="0" align="center" cellspacing="0"> <tr> <td width = "430" colspan="6" bgcolor="#CCCCCC" align="center" class="style17"> EastJet Flights </td> </tr> <tr bgcolor="#092A51"> <td width="10%" class="navbar">Flight</td> <td width="25%" class="navbar">Departing</td> <td width="15%" class="navbar" align="left">Dep</td> <td width="25%" class="navbar">Arriving</td> <td width="15%" class="navbar" align="left">Arr</td> <td width="10%" class="navbar">Aircraft</td> </tr> </table> <?php $equip = $_POST['equip']; $depart = $_POST['depart']; $arrive = $_POST['arrive']; $flighttype= $_POST['flighttype']; $sql = "SELECT * FROM flights WHERE equipment LIKE '%$equip%' AND depcode LIKE '%$depart%' AND arrcode LIKE '%$arrive%' AND type LIKE '%$flighttype%' ORDER BY departure ASC, flightnum ASC"; $result = mysql_query($sql); while ($stats = mysql_fetch_array($result)){ ?> <table width="430" border="0" align="center" cellspacing="0"> <tr class="board"> <td width="10%" class="style17"><a href="flightbid.php?section=flight&number=<?php echo $stats['flightnum'];?>"><?php echo $stats['flightnum'];?></a></td> <td width="25%" class="style16"><?php echo $stats['departure'];?></td> <td width="15%" class="style16"><?php echo $stats['deptime'];?></td> <td width="25%" class="style16"><?php echo $stats['arrival'];?></td> <td width="15%" class="style16"><?php echo $stats['arrtime'];?></td> <td width="10%" class="style16" align="right"><?php echo $stats['equipment'];?></td> </tr> </table> <?php } } else if ($section == 'flights'){ ?> <form name="flights" method="post" action="../flightbid.php?section=flights"> <table width="430" border="0" align="center"> <tr> <td colspan="2"><img src="routemap.png" width="430" /> </td> </tr> <tr> <td width="120" class="style1" align="left">Aircraft</td> <td align="left"> <select name="equip" size="1"> <option value="%" selected>All Aircraft</option> <option value="B73W">Boeing 737-700</option> </select> </td> </tr> <tr> <td width="120" class="style1" align="left">Flight Type</td> <td align="left"> <select name="flighttype" size="1"> <option value="%" selected>All Flights</option> <option value="sked">Scheduled</option> <option value="charter">Charter</option> </select> </td> </tr> <tr> <td width="120" class="style1" align="left">Departure</td> <td align="left"> <select name="depart" size="1"> <option value ="%" selected="selected">All Airports</option> <option value="KBOS">Boston</option> <option value="KMDW">Chicago</option> <option value="KCVG">Cincinnati</option> <option value="KIND">Indianapolis</option> <option value="KLAX">Los Angeles</option> <option value="KSFO">San Francisco</option> <option value="KTPA">Tampa</option> </select> </td> </tr> <tr> <td width="120" class="style1" align="left">Arrival</td> <td align="left"> <select name="arrive" size="1"> <option value ="%" selected="selected">All Airports</option> <option value="KBOS">Boston</option> <option value="KMDW">Chicago</option> <option value="KCVG">Cincinnati</option> <option value="KIND">Indianapolis</option> <option value="KLAX">Los Angeles</option> <option value="KSFO">San Francisco</option> <option value="KTPA">Tampa</option> </select> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="Submit" value="Submit" /> </td> </tr> </table> </form> <br /> </form> <br /> <table width="430" border="0" align="center" cellspacing="0"> <tr> <td width = "430" colspan="6" bgcolor="#CCCCCC" align="center" class="style17"> EastJet Flights </td> </tr> <tr bgcolor="#092A51"> <td width="10%" class="navbar">Flight</td> <td width="25%" class="navbar">Departing</td> <td width="15%" class="navbar" align="left">Dep</td> <td width="25%" class="navbar">Arriving</td> <td width="15%" class="navbar" align="left">Arr</td> <td width="10%" class="navbar">Aircraft</td> </tr> </table> <? $equip = $_POST['equip']; $depart = $_POST['depart']; $arrive = $_POST['arrive']; $flighttype = $_POST['flighttype']; $sql = "SELECT * FROM flights WHERE equipment LIKE '%$equip%' AND depcode LIKE '%$depart%' AND arrcode LIKE '%$arrive%' AND type LIKE '%$flighttype%' ORDER BY departure ASC, flightnum ASC"; $result = mysql_query($sql); while ($stats = mysql_fetch_array($result)){ ?> <table width="430" border="0" align="center" cellspacing="0"> <tr class="board"> <td width="10%" class="style17"><a href="flightbid.php?section=flight&number=<?php echo $stats['flightnum'];?>"><?php echo $stats['flightnum'];?></a></td> <td width="25%" class="style16"><?php echo $stats['departure'];?></td> <td width="15%" class="style16"><?php echo $stats['deptime'];?></td> <td width="25%" class="style16"><?php echo $stats['arrival'];?></td> <td width="15%" class="style16"><?php echo $stats['arrtime'];?></td> <td width="10%" class="style16" align="right"><?php echo $stats['equipment'];?></td> </tr> </table> <? } } elseif ($section == 'flight'){ ?> <form name="bidprocess" method="POST" action="flightbid.php?section=submitbid"> <? $sql = "SELECT * FROM flights WHERE flightnum = '$flight'"; $result = mysql_query($sql); $stats = mysql_fetch_array($result); $pax = (rand($stats["lowerlim"],$stats["upperlim"])); $cargo = (rand($stats["cargolow"],$stats["cargoup"])); ?> <center> <p><span class="style3">You are about to submit the following bid:</span></p> </center> <table width="264" border="0" align="center"> <tr> <td width="93" bgcolor="#FFFFFF" class="style1" align="left">Flight:</td> <td width="146" bgcolor="#FFFFFF" class="style16" align="left"><? echo $stats["flightnum"];?> <input type="hidden" name="flightnum" value="<?=$stats['flightnum']?>" /></td> </tr> <tr> <td class="style1" align="left">Departing:</td> <td width="146" bgcolor="#FFFFFF" class="style16" align="left"><? echo $stats["departure"];?> <input type="hidden" name="departure" value="<?=$stats['departure']?>" /> (<? echo $stats["depcode"];?>)<input type="hidden" name="depcode" value="<?=$stats['depcode']?>" /></td> </tr> <tr> <td bgcolor="#FFFFFF" align="left" class="style1">Departure Time:</td> <td width="146" bgcolor="#FFFFFF" class="style16" align="left"><? echo $stats["deptime"];?> <input type="hidden" name="deptime" value="<?=$stats['deptime']?>" /></td> </tr> <tr> <td bgcolor="#FFFFFF" class="style1" align="left">Arriving:</td> <td width="146" bgcolor="#FFFFFF" class="style16" align="left"><? echo $stats["arrival"];?> <input type="hidden" name="arrival" value="<?=$stats['arrival']?>" /> (<? echo $stats["arrcode"];?>)<input type="hidden" name="arrcode" value="<?=$stats['arrcode']?>" /></td> </tr> <tr> <td bgcolor="#FFFFFF" class="style1" align="left">Arrival Time:</td> <td width="146" bgcolor="#FFFFFF" class="style16" align="left"><? echo $stats["arrtime"];?> <input type="hidden" name="arrtime" value="<?=$stats['arrtime']?>" /></td> </tr> <tr> <td bgcolor="#FFFFFF" class="style1" align="left">Aircraft:</td> <td width="146" bgcolor="#FFFFFF" class="style16" align="left"><? echo $stats["equipment"];?> <input type="hidden" name="equipment" value="<?=$stats['equipment']?>" /></td> </tr> <tr> <td bgcolor="#FFFFFF" class="style1" align="left">Passengers:</td> <td width="146" bgcolor="#FFFFFF" class="style16" align="left"><? echo $pax ;?> <input type="hidden" name="pax" value="<?=$pax?>" /></td> </tr> <tr> <td bgcolor="#FFFFFF" class="style1" align="left">Cargo:</td> <td width="146" bgcolor="#FFFFFF" class="style16" align="left"><? echo $cargo ;?> lbs. <input type="hidden" name="cargo" value="<?=$cargo?>" /></td> </tr> </table> <?php if(isset($pilotid)){ ?> <center> <input type="submit" name="Submit" value="Submit Bid"> </center> </form> <? } } elseif ($section == 'submitbid'){ $flightnum = $_POST['flightnum']; $aircraft = $_POST['equipment']; $departure = $_POST['departure']; $deptime = $_POST['deptime']; $arrival = $_POST['arrival']; $arrtime = $_POST['arrtime']; $pax = $_POST['pax']; $cargo = $_POST['cargo']; $depcode = $_POST['depcode']; $arrcode = $_POST['arrcode']; $query1 = "SELECT gate FROM Gates WHERE city = '$departure' ORDER BY RAND()"; $result1 = mysql_query($query1); $depgate1 = mysql_fetch_array($result1); $depgate = $depgate1['gate']; $query2 = "SELECT gate FROM Gates WHERE city = '$arrival' ORDER BY RAND()"; $result2 = mysql_query($query2); $arrgate1 = mysql_fetch_array($result2); $arrgate = $arrgate1['gate']; $sql33 = "SELECT route FROM routes WHERE depart = '$depcode' AND arrival = '$arrcode'"; $result33 = mysql_query($sql33); $route1 = mysql_fetch_array($result33); $route = $route1['route']; $sql = "INSERT INTO takenbid (pilotid, flightnum, equipment, departure, deptime, depgate, arrival, arrtime, arrgate, pax, cargo, depcode, arrcode, route) VALUES('$pilotid','$flightnum','$aircraft','$departure','$deptime','$depgate','$arrival','$arrtime', '$arrgate','$pax', '$cargo','$depcode','$arrcode', '$route')"; ?> <table width = "430" align="center"> <tr> <td align="center" class="style16"> <?php echo "Your bid has been successfully submitted. You are now going back to the crewroom."; $result = mysql_query($sql); ?> <script language="javascript"> setTimeout ("location.href='http://eastjetvirtual.com/crewroom.php'", [3000]); </script> </td> </tr> </table> <?php } ?> <tr> <td height="23" background="bottombg.jpg" class="navbar"><center> Copyright © 2008-2009 EastJet Virtual Airlines </center> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/186559-php-session-login-session-error/#findComment-985496 Share on other sites More sharing options...
shadowspy1 Posted December 29, 2009 Author Share Posted December 29, 2009 This is the only page on the site where it seems that the session is having issues. Sometimes the session will take effect, and work as normal, other times, it seems nothing happens, almost as if the session variable isn't transferred through the browser. Quote Link to comment https://forums.phpfreaks.com/topic/186559-php-session-login-session-error/#findComment-985513 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.