harkly Posted February 24, 2010 Share Posted February 24, 2010 I am trying to get my page to redirect to another with a header. I am getting the "headers already sent by " error. I've checked for white space and researched but can't seem to find anything the pertains to my code. I am thinking that I am getting the error becuase I am posting to 'self'?? If someone could help me with my code or even send me to a good site that deals with this. <?php if( isset($_POST['submitLogin'])) { include('login.php'); login(); mysql_select_db('test'); $userID=$_POST["userID"]; $pswd=$_POST["pswd"]; $sql="SELECT * FROM user WHERE userID='$userID' and pswd='$pswd'"; $result=mysql_query($sql); $count=mysql_num_rows($result); while ($r=mysql_fetch_array($result)) { $exp_date=$r["exp_date"]; $todays_date=date("Y-m-d"); } if($count==1) { if ($exp_date >= $todays_date) { header('Location: aboutMe.php'); } else { echo "Billing is bad"; } } else { echo " <div id='incorrect'>Please verify the username or password.</div> <form method='post' action='' name='login' id='login'> <div id='loginForm'> <fieldset> <span class='textbox'> <label for='username'>Username: </label> <input type='text' name='userID' size='25' class='cells' value='$userID'> <br><label for='pswd'>Password: </label> <input type='password' name='pswd' size='25'class='cells' value='$pswd'> <br><label for='pswd'> </label>Remember Me: <input type='checkbox' name='Remember' value='21'> <br><label for='blank'> </label><a href='changePswd.php'>Forget Your Password?</a> <br><label for='blank'> </label><input type='image' value='Login' src='img/button_login.gif' width='64' height='25' onmouseover=\"javascript:this.src='img/button_login2.gif';\" onmouseout=\"javascript:this.src='img/button_login.gif';\"> <input type='hidden' name='submitLogin' value='true'> </span> </fieldset> </div> </form> "; } } else { echo " <form method='post' action='' name='login' id='login'> <div id='loginForm'> <fieldset> <span class='textbox'> <label for='username'>Username: </label> <input type='text' name='userID' size='25' class='cells'> <br><label for='pswd'>Password: </label> <input type='password' name='pswd' size='25'class='cells'> <br><label for='pswd'> </label>Remember Me: <input type='checkbox' name='Remember' value='21'> <br><label for='blank'> </label><a href='changePswd.php'>Forget Your Password?</a> <br><label for='blank'> </label><input type='image' value='Login' src='img/button_login.gif' width='64' height='25' onmouseover=\"javascript:this.src='img/button_login2.gif';\" onmouseout=\"javascript:this.src='img/button_login.gif';\"> <input type='hidden' name='submitLogin' value='true'> </span> </fieldset> </div> </form> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/193252-php-header/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 24, 2010 Share Posted February 24, 2010 Read the error message, it tells you where the output is occurring at that is preventing the header() redirect from working. You must find and fix whatever is causing that output. Quote Link to comment https://forums.phpfreaks.com/topic/193252-php-header/#findComment-1017565 Share on other sites More sharing options...
harkly Posted February 24, 2010 Author Share Posted February 24, 2010 From my research the error has something to do with white space, so I removed it all and still getting the error. Warning: Cannot modify header information - headers already sent by (output started at /home/content/i/d/2/id2294/html/singles/login.php:11) in /home/content/i/d/2/id2294/html/singles/login.php on line 49 Quote Link to comment https://forums.phpfreaks.com/topic/193252-php-header/#findComment-1017590 Share on other sites More sharing options...
teamatomic Posted February 24, 2010 Share Posted February 24, 2010 its in your included file, login.php. Until you change the order of your logic so the redirect happens before you load the login page which surely outputs a html form you will never get rid of this error. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/193252-php-header/#findComment-1017612 Share on other sites More sharing options...
harkly Posted February 24, 2010 Author Share Posted February 24, 2010 So I will have to find another to redirect when the user logs in correctly. Quote Link to comment https://forums.phpfreaks.com/topic/193252-php-header/#findComment-1017625 Share on other sites More sharing options...
teamatomic Posted February 24, 2010 Share Posted February 24, 2010 No, your if block contains the include and the redirect. Put the redirect BEFORE the include. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/193252-php-header/#findComment-1017682 Share on other sites More sharing options...
harkly Posted February 24, 2010 Author Share Posted February 24, 2010 I don't think that will work, I probably am missunderstanding. I am having the user log in, then the form is submitted to itself. It will either do 3 things based on if the user & pswd are valid and if the billing is up to date. Not sure how I can switch things around so that the redirect comes first. Quote Link to comment https://forums.phpfreaks.com/topic/193252-php-header/#findComment-1017685 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.