<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Check Login Info!</title> </head> <body> <?php require("connect.php"); $username=$_POST['username']; $password=$_POST['password']; $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql = "SELECT * FROM register WHERE Username='$username' AND Password='$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if($count==1) { echo "Welcome $username !"; header('Location:success.php'); } else { echo "Wrong Username or Password"; exit(); } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?> </body> </html> Code (markup): and it says Welcome faisal ! Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\final_project\check_login.php:12) in c:\program files\easyphp1-8\www\final_project\check_login.php on line 31 Code (markup): i want that when the login is successfull a new page is open and also at this page welcome "username" is shown like yahoo. any one plz check this script and do wat i need. thanks in advance.
Hi, Error code: <?php print “textâ€; header(’Location: http://www.example.com/’); ?> Php show error when you print any thing before this redirection. Solution: I am giving you a javascript + php function that will do redirection job: <?php function FunJavaScriptRedirection($url) {?> <script type=â€text/javascriptâ€> <!– window.location = “<?=$url?>†//–> </script> <?} print “testâ€; FunJavaScriptRedirection(â€http://www.example.com/â€); ?> Thanks
That will getter done for you . instead of using a javascript redirect <?php require("connect.php"); $username=$_POST['username']; $password=$_POST['password']; $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql = "SELECT * FROM register WHERE Username='$username' AND Password='$password'"; $result = mysql_query($sql); $count = mysql_num_rows($result); if($count==1) { echo "Welcome $username !"; header('Location:success.php'); } else { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Check Login Info!</title> </head> <body> Wrong Username or Password <? if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } exit(); } mysql_close($con); ?> </body> </html> PHP:
still says, Welcome faisal ! Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\final_project\check_login.php:19) in c:\program files\easyphp1-8\www\final_project\check_login.php on line 20 ???????????????
i have correct this. i use ob_start() just after the require(); and ob_end_flush just after header(); thankz for replyz men..
Yea agreed with mwasif.. I see the problem put exit(); after header('Location:success.php'); so header('Location:success.php'); exit();
thanks for the information mwasif, if u didn't tell me i will do same thing next time whenever i have that type of problem.