Jump to content

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


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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