TapeGun007 Posted August 3, 2009 Share Posted August 3, 2009 I use this same code on my laptop, it works fine, but I upload it to my web host, and it doesn't work. while($row = mysql_fetch_array($result)) { If ($row['Agent_Password']==$PassWord) { echo "Test"; header('Location: agent_mainmenu.php'); exit; } Else { $Error = "Password and/or Username invalid"; } } Any Ideas? I see the word "test" appear, and the rest of the page doesn't load and it doesn't redirect. Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/ Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 you can't echo anything if you are going to do a header redirect. try this: while($row = mysql_fetch_array($result)) { If ($row['Agent_Password']==$PassWord) { //echo "Test"; header('Location: agent_mainmenu.php'); exit; } Else { $Error = "Password and/or Username invalid"; } } Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889879 Share on other sites More sharing options...
TapeGun007 Posted August 3, 2009 Author Share Posted August 3, 2009 you can't echo anything if you are going to do a header redirect. try this: Heh, that doesn't have anything to do with it. That was just a test to see where my code was dying. Commenting that line out doesn't make the redirect work. The code simply does not redirect, and the page dies right there. Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889886 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 well, you can't echo out, and redirect. headers are just that: the head of the page. Can I see the whole code, so I can step through the logic? Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889887 Share on other sites More sharing options...
TapeGun007 Posted August 3, 2009 Author Share Posted August 3, 2009 Again, it works fine on my laptop (with IIS, and PHP 5, and mySQL installed). My local system basically mirrors my web host, thus why I'm so befuddled! But... I am also new to php (an ASP convert), so... I have to bow to other people's knowledge for a bit. Here is the code: <?php If (isset($_GET["logout"])) { setcookie("AgentName","",time()-3600); setcookie("AgentLogin","",time()-3600); setcookie("AgentEmail","",time()-3600); setcookie("AgentVass","",time()-3600); header('Location:agent_login.php'); exit(); } ?> <?php include("components/inc_header.php"); ?> <?php include("components/inc_header2.php"); ?> <!-- Begin Main Content --> <?php if (isset($_POST["fUsername"])) { $UserName = $_POST["fUsername"]; $PassWord = $_POST["fPassword"]; $con = mysql_connect("xxx","xxx","xxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(my_db, $con); $result = mysql_query("SELECT * FROM Agents WHERE Agent_Email='$UserName'"); while($row = mysql_fetch_array($result)) { If ($row['Agent_Password']==$PassWord) { setcookie("AgentName",$row['Agent_Name'],time()+3600*24); setcookie("AgentLogin","Agent_5487_Meir",time()+3600*24); setcookie("AgentEmail",$UserName,time()+3600*24); setcookie("AgentVass",$PassWord,time()+3600*24); echo "Page seems to just die right here, no redirect!"; header('Location: agent_mainmenu.php'); exit; } Else { $Error = "Password and/or Username invalid"; } } mysql_close($con); } ?> <form action="agent_login.php" method="post"> <table cellspacing="0" cellpadding="4" border="0"> <tr valign="top"> <td class="adtext" rowspan="4"> </td> <td colspan="2"><h1>Agent Login:</h1></td> </tr> <tr> <td>Username:</td><td><input type="text" name="fUsername" value="<?php if (isset($_COOKIE['AgentEmail'])) echo $_COOKIE['AgentEmail'] ?>"></input></td> </tr> <tr> <td>Password:</td><td><input type="password" name="fPassword" value="<?php if (isset($_COOKIE['AgentVass'])) echo $_COOKIE['AgentVass'] ?>"></input></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit"></input><p><span class="error"><?php if (isset($Error)) echo $Error; ?></span></td> </tr> <tr><td colspan="2" align="center"><a href="agent_login.php?logout=true">Log Out</a></td></tr> </table> </form> <!-- End Main Content --> Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889904 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 do components/inc_header.php and components/inc_header2.php output anything? I know I'm beating a dead horse, but if *anything* is outputted, it won't do a header redirect. try this from your hosting server: <?php header("location:http://google.com"); exit(); ?> if it redirects, then it's not the hosting server, its the code. Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889905 Share on other sites More sharing options...
TapeGun007 Posted August 3, 2009 Author Share Posted August 3, 2009 The headers are just HTML code (that's use on every page), nothing else. Just saving lines of code by including it. Then if I edit the include, it fixes ALL the pages. Ok, you win. The above code with nothing else worked fine. So... uh... I don't know it works fine locally. *shrug* Any suggestions on how to accomplish the same thing a different way? Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889909 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 put your check before your header: <?php If (isset($_GET["logout"])) { setcookie("AgentName","",time()-3600); setcookie("AgentLogin","",time()-3600); setcookie("AgentEmail","",time()-3600); setcookie("AgentVass","",time()-3600); header('Location:agent_login.php'); exit(); } if (isset($_POST["fUsername"])) { $UserName = $_POST["fUsername"]; $PassWord = $_POST["fPassword"]; $con = mysql_connect("xxx","xxx","xxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(my_db, $con); $result = mysql_query("SELECT * FROM Agents WHERE Agent_Email='$UserName'"); while($row = mysql_fetch_array($result)) { If ($row['Agent_Password']==$PassWord) { setcookie("AgentName",$row['Agent_Name'],time()+3600*24); setcookie("AgentLogin","Agent_5487_Meir",time()+3600*24); setcookie("AgentEmail",$UserName,time()+3600*24); setcookie("AgentVass",$PassWord,time()+3600*24); header('Location: agent_mainmenu.php'); exit; } Else { $Error = "Password and/or Username invalid"; } } mysql_close($con); } ?> <?php include("components/inc_header.php"); ?> <?php include("components/inc_header2.php"); ?> <!-- Begin Main Content --> <form action="agent_login.php" method="post"> <table cellspacing="0" cellpadding="4" border="0"> <tr valign="top"> <td class="adtext" rowspan="4"> </td> <td colspan="2"><h1>Agent Login:</h1></td> </tr> <tr> <td>Username:</td><td><input type="text" name="fUsername" value="<?php if (isset($_COOKIE['AgentEmail'])) echo $_COOKIE['AgentEmail'] ?>"></input></td> </tr> <tr> <td>Password:</td><td><input type="password" name="fPassword" value="<?php if (isset($_COOKIE['AgentVass'])) echo $_COOKIE['AgentVass'] ?>"></input></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Submit"></input><p><span class="error"><?php if (isset($Error)) echo $Error; ?></span></td> </tr> <tr><td colspan="2" align="center"><a href="agent_login.php?logout=true">Log Out</a></td></tr> </table> </form> <!-- End Main Content --> EDIT* Forgot to remove the echo Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889913 Share on other sites More sharing options...
TapeGun007 Posted August 3, 2009 Author Share Posted August 3, 2009 I did as you suggested and it didn't work initially. So I took your google code, pasting it at the top, and it worked fine. Then I decided to clear out IE8 cache, put my code back in, and added the cookies back in. Everything works fine again! Thank you for your expertise, you saved me hours of time!!!! Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889932 Share on other sites More sharing options...
jonsjava Posted August 3, 2009 Share Posted August 3, 2009 glad to help Quote Link to comment https://forums.phpfreaks.com/topic/168686-solved-header-redirect-doesnt-work/#findComment-889937 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.