Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>header('Location: http://example.com/Account/index.php'); exit; </code></pre> <p>is one way to do this but you can use output buffering to get around this problem, with the overhead of all of your output to the browser being buffered in the server until you send it. You can do this by calling <code>ob_start()</code> and <code>ob_end_flush()</code> in your script, or setting the output_buffering configuration directive on in your php.ini or server configuration files.</p> <p>EDIT AND APPEND SOLUTION: ------></p> <p>You can use Output Buffering as</p> <pre><code> &lt;?php ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="DBase"; // Database name $tbl_name="customers"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from the form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $myusername = stripslashes($myusername); $mypassword = md5($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE Username='$myusername' and Password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_register("myusername"); session_register("mypassword"); header("location:/Account/index.php"); } else { echo "Wrong Username or Password."; } ob_end_flush(); ?&gt; </code></pre> <p>The problem is that we cannot send the header after we start sending the output. To solve this we buffer the output. The function ob_start turns output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer. So the echo output will be buffered. Next we send the header without any problem as we've not yet spit out any output. Finally we call ob_end_flush to flush the internal buffer contents and to stop output buffering.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload