karthikjayraj Posted October 21, 2010 Share Posted October 21, 2010 Hi, I found a code for login page on web which would check against the database and login, I wanted to modify it so that once the password is verified the user will be directed to a new page with the session variables also active. I read about " header()" functionality which would achieve this so i added this to the code but my code seems to fail with the error "Cannot modify header information - headers already sent by (output started at C:\xampp\phpMyAdmin\scripts\login1.php:7) in C:\xampp\phpMyAdmin\scripts\login1.php on line 10 " The code for login1.php is as below- For quick understanding i have removed all the section related to DB validation ..so the below code must activate the next page "add_entry2.php" immediately after submit button is pressed. Please see below.. Thanks in advance. <html> <head> <title>Login</title> </head> <body> <?php if (isset($_POST['submit'])) {if(!$_POST['uname'] | !$_POST['passwd']){die('You did not fill in a required field.'); } header('Location: add_entry2.php');} else {// if form hasn't been submitted ?> <h1>Login</h1> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table align="center" border="1" cellspacing="0" cellpadding="3"> <tr><td>Username:</td><td> <input type="text" name="uname" maxlength="40"> </td></tr> <tr><td>Password:</td><td> <input type="password" name="passwd" maxlength="50"> </td></tr> <tr><td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 21, 2010 Share Posted October 21, 2010 Did you read THIS STICKY regarding that subject? Quote Link to comment Share on other sites More sharing options...
karthikjayraj Posted October 21, 2010 Author Share Posted October 21, 2010 Yes I did and have checked for 1.whitespaces/unwanted lines but dint get through 2. My form will not post anything on the output after it has been submitted for the first time..what i mean is i am not posting anything before the Header() function. OR if you think there is some other command where i can direct my page based on success of some if condition NOT click then please do let me know. Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted October 21, 2010 Share Posted October 21, 2010 Yes you are. All of this is sent immediately upon page load: <html> <head> <title>Login</title> </head> <body> Quote Link to comment Share on other sites More sharing options...
karthikjayraj Posted October 21, 2010 Author Share Posted October 21, 2010 Thanks for your instant replies Pikachu.. I changed the code to look like this below and it worked!!!! <?php if (isset($_POST['submit'])) { if(!$_POST['uname'] | !$_POST['passwd']) {print'You did not fill in a required field.'; } header('Location: add_entry2.php'); }else{ echo "<form action=\"login1.php\" method=\"POST\">"; echo "Username: <input name=\"uname\" size=\"15\"><br />"; echo "Password: <input type=\"password\" name=\"passwd\" size=\"8\"><br />"; echo "<input type=\"submit\" name=\"submit\" value=\"Login\">"; echo "</form>";} ?> 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.