graham23s Posted November 30, 2007 Share Posted November 30, 2007 Hi Guys, in my login page i redirect to a second page logincheck.php to check the details then redirect to the myaccount.php page when all is well, but i'm not sure how to put the code in the 1 page, because headers can't be sent twice error login.php <?php echo ("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#FF0000\"> <tr> <td valign=\"top\">"); ## login echo ("<form action=\"logincheck.php\" method=\"POST\">"); echo ("<table class=\"tablesmain\" align=\"left\" width=\"300\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">"); echo ("<tr>"); echo ("<td class=\"header_boxes\" colspan=\"2\" align=\"left\"><span class=\"header_txt\">Members Login</span></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td align=\"right\"><b>Username:</b></td><td align=\"left\"><input type=\"text\" name=\"username\"></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td align=\"right\"><b>Password:</b></td><td align=\"left\"><input type=\"password\" name=\"password\"></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td colspan=\"2\" align=\"right\">[<a class=\"foot_links\" href=\"recoverpassword.php\">FORGOT PASSWORD</a>] <input type=\"submit\" class=\"btn\" name=\"submit\" value=\"Login\"></td>"); echo ("</tr>"); echo ("</table></form>"); ## new table cell data echo ("</td>"); echo ("<td valign=\"top\" align=\"left\">"); echo ("<ul>"); echo ("<li>Search performers by location</li>"); echo ("<li>Send unlimited messages</li>"); echo ("<li>Leave comments on performers profiles</li>"); echo ("<li>Rate your fellow members</li>"); echo ("<li>Write your own blog</li>"); echo ("<li><b>Plus MUCH more join today!</b></li>"); echo ("<li><a class=\"foot_links\" href=\"register.php\">Not a member yet? sign up here!</a></li>"); echo ("</ul>"); //echo ("<br />"); echo ("<img src=\"images/placeholder.jpg\">"); ## end html tables echo ("</td> </tr> </table>"); ?> <?php // include the footer...//////////////////////////////////////////////////////////// include("includes/footer.php"); ?> logincheck.php <?php require("includes/db_connection.php"); ## The all important post variables $var_username = mysql_real_escape_string(trim($_POST['username'])); $var_password = mysql_real_escape_string(trim($_POST['password'])); ## blank submission if(empty($var_username) || empty($var_password)) { echo '<div align="center" style="border: 1px solid black;padding:10px; background: yellow; color: #000000; font-size: 14px;"><b>You never filled in both fields, please fill them both in.</b></div><br />'; exit; } $q = "SELECT `id`,`username`,`password` FROM `users` WHERE `username`='$var_username' AND `password`='$var_password' LIMIT 1"; $r = mysql_query($q); $row = mysql_fetch_array($r); $any_results = mysql_num_rows($r); if($any_results != 1) { echo '<div align="center" style="border: 1px solid black;padding:10px; background: yellow; color: #000000; font-size: 14px;"><b>We can\'t find that username/password combination in the database, please re-check your login details.</b></div><br />'; exit; } else { ## update the login timer $var_update_time_query = mysql_query("UPDATE `users` SET `lastlogin` = now() WHERE `username`='$var_username' AND `password`='$var_password'"); ## There was a result back session_start(); $_SESSION['id'] = $row['id']; $_SESSION['username'] = $row['username']; $_SESSION['loggedin'] = 'yes'; ## redirect to members page header("Location:myaccount.php"); } ?> is there any way around this or will i just need to stick with the 2 pages? thanks guys Graham Quote Link to comment Share on other sites More sharing options...
Distant_storm Posted November 30, 2007 Share Posted November 30, 2007 at the top of your first page put if (isset($_POST['submit'])) { /do the processing of logincheck.php exit(); } That says if the value of $_POST which is the form method value of submit which is your button is sent then process the data Quote Link to comment Share on other sites More sharing options...
graham23s Posted November 30, 2007 Author Share Posted November 30, 2007 Hi Mate, what i was trying to do also is keep the layout of the site the same, if i did that i would need to echo out the page header (html) then redirect them to myaccount.php cheers Graham Quote Link to comment 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.