jquery - PHP Header Location not working With BootStrap 3 [Normal header location working fine] -
this question has answer here:
- how fix “headers sent” error in php 11 answers
i facing php header redirection issue bootstrap, please find code below,
index file:
<?php if(!isset($_session)){ session_start(); } include("db.php"); ?> <html> <head> <title> </title> <!-- jquery imports <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>--> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <!-- latest compiled , minified css --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1 /css/bootstrap.min.css"> <!-- latest compiled , minified javascript <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"> </script>--> <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.min.js"></script> <!-- custom js --> <script src="js/bookrate.js"></script> <style type="text/css"> body{padding-top:20px;} </style> </head> <body> <div class="cycle"> <h3 class="text-center">--</h3><br> <h2 class="text-center"><small>admin panel</small></h2><br> </div> <div class="container"> <div class="row"> <div class="col-md-4 col-md-offset-4"> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">please sign in</h3> </div> <div class="panel-body"> <form id="adminlogin" method="post"> <fieldset> <div class="form-group"> <input class="form-control" placeholder="e-mail" name="email" type="text" id="email"> </div> <div class="form-group"> <input class="form-control" placeholder="password" name="password" type="password" value="" id="password"> </div> <div class="checkbox"> <label> <input name="remember" type="checkbox" value="remember me"> remember me </label> </div> <input class="btn btn-lg btn-success btn-block" type="submit" value="login"> </fieldset> </form> </div> </div> </div> </div> </div> </body> </html>
and db file is:
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('could not connect: ' . mysql_error()); } mysql_select_db('mydb'); ?>
ajax admin login page:
<?php ob_start(); session_start(); include("db.php"); $adminemail =$_post['email']; $adminpassword = $_post['password']; $adminloginqry = "select email `users` (email='$adminemail') , password='$adminpassword'"; $retval = mysql_query($adminloginqry); if(mysql_num_rows($retval)==1) { header("location: main.php"); exit; }else{ echo "<span style='color:red;'>please enter valid username , password. </span>"; } ?>
main.php
<?php echo "my menu page"; ?>
once enter email id , password, on click of login button both , post requests triggered, how both requests getting triggere not able understand ?. still working fine, able confirm mozilla firefox firebug (developer console).
header location redirection not happening main.php page after login success. please tell me wrong here..
this question not having answer already, me header location working fine, not working bootstrap 3. please not mark duplicate.
the problem headers sent, or in simple language output sent browser when header() function invoked.
the best solution not pass headers (send html/output browser) till point header() function fired.
solution :
$url = "main.php"; if (!headers_sent()) { header('location: '.$url); exit; } else { echo '<script type="text/javascript">'; echo 'window.location.href="'.$url.'";'; echo '</script>'; exit; }
this simple code trick you. check if headers not sent, call php’s header function redirect. if headers sent, use javascript redirect url want.
Comments
Post a Comment