Jump to content

[SOLVED] Forward to page, if username is valid...


Gnub

Recommended Posts

Ok, i have a simple script that checks the username and password of a user, if it is true, it send the person to address1, if it is false, it send the user to another page.

 

I've covered the basics, but im gettting a:

 

"

Warning: Cannot modify header information - headers already sent by (output started at /web/log.php:9)

in /web/log.php on line 21

"

 

<?PHP
$User = $_POST["Username"];
$Password = $_POST["Password"];

$sql = "Select * FROM `Account` WHERE `Username` = '$User' AND `Password` = '$Password'";


if (mysql_num_rows($result) >"0")
{
header("location: http://www.Yahoo.com");
echo 'Login Details accepted, you are now being forwarded to the main page...';
}
if (mysql_num_rows($result) =="0")
{
echo 'You are now being forwarded to somewhere else;
header("location: http://www.bbc.co.uk");
}
?>

you cant output text to the browser and then use a header redirect.

 

read the faqs and the stickies, especially the ones in all caps before you post next time.

 

http://www.phpfreaks.com/forums/index.php/topic,95562.0.html

http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

Make 100% sure that you have no HTML tags above this code:

(In other words):

<HTML><HEAD></HEAD>

<BODY>

<?PHP
$User = $_POST["Username"];
$Password = $_POST["Password"];

$sql = "Select * FROM `Account` WHERE `Username` = '$User' AND `Password` = '$Password'";


if (mysql_num_rows($result) >"0")
{
header("location: http://www.Yahoo.com");
echo 'Login Details accepted, you are now being forwarded to the main page...';
}
if (mysql_num_rows($result) =="0")
{
echo 'You are now being forwarded to somewhere else;
header("location: http://www.bbc.co.uk");
}
?>

</BODY>

</HTML>

 

 

 

Any HTML tags before this will cause the header to function improperly.

remove the echo's

 

if you MUST have a page telling the user their being redirected then create a redirect page that uses javascript to redirect them

 

 

as a side note

 

i'm sure you should have

if (mysql_num_rows($result) >0)

instead of

if (mysql_num_rows($result) >"0")

same for the ==

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.