I've seen the use of header in the php to redirect to a page.
I've used the method in the code below and the a redirect error as given below the code.
I need to know what went wrong with the code.
Here is the code (php) :
<?php
/**
* Created by PhpStorm.
* User: Priyabrata
* Date: 3/18/14
* Time: 8:58 PM
*/
function connect_to_db($uid, $pass){
$con=mysqli_connect("localhost", "root", "12345", "MyDB");
if (mysqli_connect_errno()){
echo "Failed to establish link!!";
}else{
echo mysqli_connect_error();
}
$result=mysqli_query($con, "SELECT `pwd` from `login_table` where `uid` = "."'".$uid."'");
if (!$result){
echo "Error!!";
exit();
}
while($xx = mysqli_fetch_array($result)){
if ($xx['pwd'] == hash("MD5", $pass)){
header("location:../Html/Login-Existing-Users1_success.htm");
exit();
}else{
echo "Invalid Login Credentials!!";
exit();
}
}
mysqli_close($con);
}
function validate_credentials(){
if ((isset($_POST["username"]))&&(isset($_POST["password"]))){
$uid = $_POST["username"];
$pwd = $_POST["password"];
if (($uid == "")||($pwd == "")){
echo "Please enter User name and password";
}else{
//Check user name and password
connect_to_db($uid, $pwd);
}
}else{
echo "Please enter User name and password";
}
}
validate_credentials();
Here is the error I get, instead of a redirect when uploaded to the server:
Warning: Cannot modify header information - headers already sent by (output started at /home/opticfhb/public_html/helpvssupport.net/login.php:19) in /home/opticfhb/public_html/helpvssupport.net/login.php on line 27
Additional Info : This works perfectly in my local machine and creates the problem in the server.