url - Php Redirect to a webpage (html) -
i've seen use of header in php redirect page.
i've used method in code below , redirect error given below code.
i need know went wrong code.
here code (php) :
<?php /** * created 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 establish link!!"; }else{ echo mysqli_connect_error(); } $result=mysqli_query($con, "select `pwd` `login_table` `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 , password"; }else{ //check user name , password connect_to_db($uid, $pwd); } }else{ echo "please enter user name , password"; } } validate_credentials();
here error get, instead of redirect when uploaded server:
warning: cannot modify header information - headers sent (output started @ /home/opticfhb/public_html/helpvssupport.net/login.php:19) in /home/opticfhb/public_html/helpvssupport.net/login.php on line 27
additional info : works in local machine , creates problem in server.
you can't call header()
after you've echoed output. http requests contain header information , data. output part of data, , data comes after headers have been sent.
php has function called headers_sent check whether or not headers have been sent or not. might consider writing function issues location header if haven't been, or echo out simple redirect html if have -- perhaps including tag in <head>
:
<meta http-equiv="refresh" content="0;http://www.website.com/redirect/url" />
Comments
Post a Comment