Jump to content

Header may not contain more than a single header....


conman20

Recommended Posts

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>

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)

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'];?>">

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>

 

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... 

 

 

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!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.