conman20 Posted January 2, 2010 Share Posted January 2, 2010 Hello there,can anyone help me pls..am really a newbie,start to study php using wrox books,am on the user login part right now. got a prblem with header.....Warning: Header may not contain more than a single header, new line detected. in C:\Inetpub\wwwroot\testuserlogin\login.php on line 8 this is the login.php <?php session_start(); $_SESSION['logged'] = 0; if (isset($_POST['submit'])){ if ($_POST['username'] == "wroxbooks" && $_POST['password'] == "aregreat") { $_SESSION['logged'] = 1; header("Refresh: 5; URL=" .$_POST['redirect'] . ""); echo "You are being redirected to your original page requests!<br>"; echo "(If your browser doesn't support this, <a href=\"". $_POST['redirect']."\">click here</a>)"; }else{ ?> <html> <head> <title>Beginning PHP, Apache, MySQL Web Development</title> </head> <body> Invalid Username and/or Password<br><br> <form action="login.php" method="post"> <input type="hidden" name="redirect" value="<?php echo $_POST['redirect'];?>"> Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br><br> <input type="submit" name="submit" value="Login"> </form> <?php } } else { ?> <html> <head> <title>Beginning PHP, Apache, MySQL Web Development</title> </head> <body> You must be logged in to view this page<br><br> <form action="login.php" method="post"> <input type="hidden" name="redirect" value="<?php echo $_GET['redirect'];?>"> Username: <input type="text" name="username"><br> Password: <input type="password" name="password"><br><br> <input type="submit" name="submit" value="Login"> </form> <?php } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 2, 2010 Share Posted January 2, 2010 Try this.. Im a little tired at the moment header('Refresh: 5; url="'.$_POST['redirect'].'"'); Quote Link to comment Share on other sites More sharing options...
conman20 Posted January 2, 2010 Author Share Posted January 2, 2010 Hi buddsky....am still getting the same error Quote Link to comment Share on other sites More sharing options...
mattal999 Posted January 2, 2010 Share Posted January 2, 2010 Try echoing the $_POST['redirect'] part. If it contains a \n or \r, then it will break the header request. Try doing this: header('Refresh: 5; url="'.trim($_POST['redirect']).'"'); Quote Link to comment Share on other sites More sharing options...
conman20 Posted January 2, 2010 Author Share Posted January 2, 2010 matt i still have the same warning..i cant believe this program isnt working,i just copy it from the book Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 2, 2010 Share Posted January 2, 2010 var_dump($_POST['redirect']) and show us what's inside Quote Link to comment Share on other sites More sharing options...
conman20 Posted January 2, 2010 Author Share Posted January 2, 2010 hi matt; this is the last result when i run the program...afterwards it went back to the same page. string(129) " Notice: Undefined index: redirect in C:\Inetpub\wwwroot\testuserlogin\login.php on line 39 " You are being redirected to your original page request! (If your browser doesn't support this, click here) Quote Link to comment Share on other sites More sharing options...
conman20 Posted January 2, 2010 Author Share Posted January 2, 2010 ooopss that was for mchl... Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 2, 2010 Share Posted January 2, 2010 So it boils down to this line <input type="hidden" name="redirect" value="<?php echo $_GET['redirect'];?>"> You have no 'redirect' variable defined in your GET string, and PHP complains about it. try changing it to this <input type="hidden" name="redirect" value="<?php if(isset($_GET['redirect'])) echo $_GET['redirect'];?>"> Quote Link to comment Share on other sites More sharing options...
conman20 Posted January 2, 2010 Author Share Posted January 2, 2010 hi again,this was the last result... string(0) "" You are being redirected to your original page request! (If your browser doesn't support this, click here) then went back to the same page. i will paste the other 2 files im using, perhaps u can see some other error... auth.inc.php <?php session_start(); if ($_SESSION['logged'] != 1) {$redirect = $_SERVER['PHP_SELF']; header("URL=login.php?redirect=$redirect"); echo "You are being redirected to the login page!<br>"; echo "(If your browser doesn't support this, <a href=\"login.php?redirect=$redirect\">click here</a>)"; die();} ?> template.php <?php include 'auth.inc.php'; ?> <html> <head> <title>Beginning PHP,Apache,MysSQL Web Development</title> </head> <body> <h1>This is the Template Page</h1> </body> </html> Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 2, 2010 Share Posted January 2, 2010 The original error should be gone now. You should be able to run the script by running http://yourdomain/login.php?redirect=http://redirect.url And you can remove var_dump now. Quote Link to comment Share on other sites More sharing options...
conman20 Posted January 2, 2010 Author Share Posted January 2, 2010 mchl, i ran the link you gave,i input username and password and the last result was ...cannot display the webpage then the url above became http://redirect.url/ seems it didnt find the page.does it have something to do with my browser or IIS config,or php config? i really need to get this program running so ill be able to move on user login with database... Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 2, 2010 Share Posted January 2, 2010 You're supposed to change yourdomain to your actual domain, and redirect.url to url you want to get redirected. Quote Link to comment Share on other sites More sharing options...
conman20 Posted January 2, 2010 Author Share Posted January 2, 2010 it worked mchl! the one i ran..http://localhost/testuserlogin/login.php?redirect=http://localhost/testuserlogin/template.php btw,is there any way to modify the program instead of typing this url ? Quote Link to comment Share on other sites More sharing options...
Mchl Posted January 2, 2010 Share Posted January 2, 2010 There is of course. As I understand you're doing some examples from the book. Perhaps they have reason to do it this way? Quote Link to comment Share on other sites More sharing options...
conman20 Posted January 2, 2010 Author Share Posted January 2, 2010 i started with this e-book 2 weeks ago and i had no problem with the given examples until this one... actually i was stuck up.so i created a posting here.i guess i have to dig a little deeper to come up with a conclusion on why did they do it that way.i hope ill be getting an answer when i get into more complex user login programs.thanks a lot mchl,i appreciate it.god bless! 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.