i have two textbox and i check if the user insert this username and this password then go to another page else write wrong data and it is the code <?php $name="test"; $password="test"; if($_POST["admin_name"]==$name and $_POST["pass"]==$password) { header("location: /form/index.php");} else {echo"wrong data";} ?> but this code give me this error Warning: Cannot modify header information - headers already sent i donot know what i do please i want help thank you
If you are using header(), you have to make sure that there is no other output being generated before you call it. A common cause of this problem is blank lines in your file before the first <? It's also possible that you've saved your PHP file as unicode with BOM (byte-order mark).
i have a table on the page before the code and i save the php file ANSI not unicode what will i do????
You can't have any output before the header() call. Also, it doesn't make any sense to generate output if you are going to be sending a redirect header, since the browser will not display it. But if it's too much work to reorganise your code, you can just cheat, and use output buffering. <? ob_start(); // output the table if (whatever_condition) { ob_end_clean(); header("Location: elsewhere"); exit; } ob_end_flush(); // do something else ?> PHP:
header() always() use before rendering any output. so u can use javascript for this <?php $name="test"; $password="test"; if($_POST["admin_name"]==$name and $_POST["pass"]==$password) { echo "<script language='javascript'>window.location='/form/index.php'</script>";} else {echo"wrong data";} ?> OK
Don't use Javascript, because the user can disable it and then your script wouldn't redirect anymore.