2016-02-27 160 views
0

工作,我创建一个登录脚本它在PC上的浏览器工作正常,但是当手机浏览器使用相同的代码,它不能重定向我在回家page.So我不明白问题出在哪里。任何人都可以帮助我? 守则的login.php登录不上手机浏览器

<?php 
ob_start(); 
@session_start(); 
include 'conn.php'; 

?> 
<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 

     <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame 
     Remove this if you use the .htaccess --> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 

     <title>Admin Login</title> 
     <meta name="description" content=""> 
     <meta name="author" content="Bheem"> 

     <meta name="viewport" content="width=device-width; initial-scale=1.0"> 

     <!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references --> 
     <link rel="shortcut icon" href="/favicon.ico"> 
     <link rel="apple-touch-icon" href="/apple-touch-icon.png"> 
     <link rel="stylesheet" type="text/css" href="css/admin_style.css" /> 
    </head> 

    <body> 
     <div> 
      <header> 

      </header> 
      <nav> 

      </nav> 

      <div> 
<div id="login-content-wrp"> 
     <h2 class="login-tit" >Admin Login</h2> 

     <form name="login" onsubmit="return val()" method="post"> 
     <div id="login-content" > 
      <div class="con-row" > 

      <input type="text" autocomplete="off" class="txt-box" placeholder="User Name" name="txtuname"/> 
      <span class="error" id="blank-user" >Please Enter User Name</span> 

      </div> 
      <div class="con-row" > 

      <input type="password" autocomplete="off" class="txt-box" placeholder="Password" name="txtpass" /> 
      <span class="error" id="blank-password" >Please Enter Password</span> 
      </div> 
      <div class="con-row" > 

      <input type="submit" class="btn-login" name="btnlogin" value="Login" /> 
      <span class="error" id="invaild-user-pass" >Please Enter Valid User Name OR Password!</span> 
      </div> 
     </div> 
     </form> 
     </div> 
      </div> 

      <footer> 

      </footer> 
     </div> 

<script> 
    function val() 
    { 
     if(document.login.txtuname.value=='') 
     { 
      document.getElementById("blank-user").style.display = "block"; 

      document.login.txtuname.focus(); 
      return false; 
     } 
     else{ 
      document.getElementById("blank-user").style.display = "none"; 
     } 
     if(document.login.txtpass.value=='') 
     { 
      document.getElementById("blank-password").style.display = "block"; 
      document.login.txtpass.focus(); 
      return false; 
     } 
     else{ 
      document.getElementById("blank-password").style.display = "none"; 
     } 
     return true; 
    } 
</script> 
<?php 
if(!isset($_SESSION['admin_id'])) 
{ 
if(isset($_POST['btnlogin'])) 
{ 
    $uname=mysql_real_escape_string($_POST['txtuname']); 
    $pass=mysql_real_escape_string($_POST['txtpass']); 
    $query = "select * from tbl_admin where user_name='$uname' and password=md5('$pass')"; 
    $result = mysql_query($query); 

    if(mysql_num_rows($result) == 1) 
    { 
     $row = mysql_fetch_array($result); 
     $_SESSION['admin_id'] = $row['user_name']; 
     $_SESSION['admin_name'] = $row['name']; 
     $_SESSION['admin_img'] = $row['image']; 
     $_SESSION['admin_pass'] = $row['password']; 
     setcookie('adminname',$row['user_name'],time()+(60 * 60 * 24 * 30), "/"); 
     setcookie('password',$row['password'],time()+(60 * 60 * 24 * 30), "/"); 
     header("location:home.php"); 
     exit ; 
    } 
    else { 
?> 
<script type="text/javascript"> 
    document.getElementById("invaild-user-pass").style.display = "block"; 
</script> 
<?php 
} 
} 
} 
?> 
<?php 
//ob_end_flush(); 
?> 
</body> 
</html> 

守则Home.php

<!DOCTYPE html> 
<html lang="en"> 
<?php 
include '../conn.php'; 
    ob_start(); 
@session_start(); 
if(!isset($_SESSION['admin_id'])){ 
die("<script>location.href = 'login.php'</script>"); 
} 
?> 
    <head> 
     <?php include 'header_viewport.php'; ?> 

     <title>Admin Section</title> 

     <?php 
     include 'header_links.php'; 
     ?> 
    </head> 

    <body class="nav-md"> 

     <div class="container body"> 

      <div class="main_container"> 

       <div class="col-md-3 left_col"> 
        <div class="left_col scroll-view"> 

         <?php 
         include "sidebar_menu.php"; 

         include "navigation.php"; 
         ?> 

         <!-- page content --> 
         <div class="right_col" role="main"> 

          <!-- top tiles --> 
          <!-- <div class="row tile_count"> 
          <div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count"> 
          <div class="left"></div> 
          <div class="right"> 
          <span class="count_top"><i class="fa fa-user"></i> Total Users</span> 
          <div class="count">2500</div> 
          <span class="count_bottom"><i class="green">4% </i> From last Week</span> 
          </div> 
          </div> 
          <div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count"> 
          <div class="left"></div> 
          <div class="right"> 
          <span class="count_top"><i class="fa fa-clock-o"></i> Average Time</span> 
          <div class="count">123.50</div> 
          <span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>3% </i> From last Week</span> 
          </div> 
          </div> 
          <div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count"> 
          <div class="left"></div> 
          <div class="right"> 
          <span class="count_top"><i class="fa fa-user"></i> Total Males</span> 
          <div class="count green">2,500</div> 
          <span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>34% </i> From last Week</span> 
          </div> 
          </div> 
          <div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count"> 
          <div class="left"></div> 
          <div class="right"> 
          <span class="count_top"><i class="fa fa-user"></i> Total Females</span> 
          <div class="count">4,567</div> 
          <span class="count_bottom"><i class="red"><i class="fa fa-sort-desc"></i>12% </i> From last Week</span> 
          </div> 
          </div> 
          <div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count"> 
          <div class="left"></div> 
          <div class="right"> 
          <span class="count_top"><i class="fa fa-user"></i> Total Collections</span> 
          <div class="count">2,315</div> 
          <span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>34% </i> From last Week</span> 
          </div> 
          </div> 
          <div class="animated flipInY col-md-2 col-sm-4 col-xs-4 tile_stats_count"> 
          <div class="left"></div> 
          <div class="right"> 
          <span class="count_top"><i class="fa fa-user"></i> Total Connections</span> 
          <div class="count">7,325</div> 
          <span class="count_bottom"><i class="green"><i class="fa fa-sort-asc"></i>34% </i> From last Week</span> 
          </div> 
          </div> 

          </div> --> 
          <!-- /top tiles --> 

          <div class="row"> 
           <div class="col-md-12 col-sm-12 col-xs-12"> 
            <div class="dashboard_graph"> 

             <div class="row x_title"> 
              <div class="col-md-6"> 
               <h3>Customers <small>Details</small></h3> 
              </div> 
              <table class="table"> 

               <thead> 

                <tr> 

                 <th>#</th> 

                 <th>Name</th> 

                 <th>Phone No.</th> 

                 <th>Email</th> 
                 <th>Product</th> 
                 <th>Start Date</th> 
                 <th>End Date</th> 
                 <th>Status</th> 


                </tr> 

               </thead> 

               <tbody> 
                <?php 
                $count = 1; 
                $query = "select c.*,cp.product_pk,cp.start_date,cp.end_date,p.name as product_name from tbl_customer c left join customer_products cp on c.pk=cp.customer_pk left join tbl_product p on p.pk=cp.product_pk limit 5"; 
                $result = mysql_query($query)or die(mysql_error()); 
                while($row = mysql_fetch_array($result)) 
                { 
                ?> 
                <tr> 
                 <td><?php echo $count; ?></td> 
                 <td><?php echo $row['name'] ?></td> 
                 <td><?php echo $row['mobile'] ?></td> 
                 <td><?php echo $row['email'] ?></td> 
                 <td><?php echo $row['product_name'] ?></td> 
                 <td><?php echo $row['start_date'] ?></td> 
                 <td><?php echo $row['end_date'] ?></td> 
                 <td><?php if($row['status']==1){ 
                  ?> 
                  <input disabled="disabled" type="checkbox" checked="checked" /> 
                  <?php 

                 } 
else{ 
    ?> 
    <input type="checkbox" /> 
    <?php 
} 
                 ?></td> 

                </tr> 
                <?php 
                $count = $count + 1; 
                } 
                ?> 
               </tbody> 
              </table> 

             </div> 

             <div class="col-md-9 col-sm-9 col-xs-12"> 

             </div> 
             <div class="col-md-3 col-sm-3 col-xs-12 bg-white"> 

             </div> 

             <div class="clearfix"></div> 
             <a href="customers.php" class="btn btn-primary btn-xs pull-right" >View All</a> 
             <br> 
            </div> 
           </div> 

          </div> 
          <br /> 

          <div class="row"> 
           <div id="user_sug" class="col-md-12 col-sm-12 col-xs-12"> 
            <div class="x_panel"> 
             <div class="x_title"> 
              <h2>User Suggestions</h2> 
              <ul class="nav navbar-right panel_toolbox"> 
               <li> 
                <a class="collapse-link"><i class="fa fa-chevron-up"></i></a> 
               </li> 

               <li> 
                <a class="close-link"><i class="fa fa-close"></i></a> 
               </li> 
              </ul> 
              <div class="clearfix"></div> 
             </div> 
             <div class="x_content"> 
              <div class="dashboard-widget-content"> 

               <ul class="list-unstyled timeline widget"> 
                <?php 
                $query = "select * from tbl_suggestion order by date desc limit 5"; 
                $result = mysql_query($query) or die(mysql_error()); 
                while($row = mysql_fetch_array($result)) 
                { 
                ?> 
                <li> 
                 <div class="block"> 
                  <div class="block_content"> 
                   <h2 class="title"><a><?php echo $row['email'] ?></a></h2> 
                   <div class="byline"> 
                    <span><?php echo date('d M Y',strtotime($row['date'])); ?></span> 
                   </div> 
                   <p class="excerpt"> 
                    <?php echo $row['suggestion']; ?> 
                   </p> 
                  </div> 
                 </div> 
                </li> 
                <?php 
                } 
                ?> 
             <br>   
             <a href="suggestions.php" class="btn btn-primary btn-xs pull-right" >View All</a> 


               </ul> 
              </div> 
             </div> 
            </div> 
           </div> 

           <div class="col-md-12 col-sm-12 col-xs-12"> 

            <div class="row"> 

             <div id="user_enq" class="col-md-12 col-sm-12 col-xs-12"> 
              <div class="x_panel"> 
               <div class="x_title"> 
                <h2>User Enquiry </h2> 
                <ul class="nav navbar-right panel_toolbox"> 
                 <li> 
                  <a class="collapse-link"><i class="fa fa-chevron-up"></i></a> 
                 </li> 
                 <!-- <li class="dropdown"> 
                 <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a> 
                 <ul class="dropdown-menu" role="menu"> 
                 <li><a href="#">Settings 1</a> 
                 </li> 
                 <li><a href="#">Settings 2</a> 
                 </li> 
                 </ul> 
                 </li> --> 
                 <li> 
                  <a class="close-link"><i class="fa fa-close"></i></a> 
                 </li> 
                </ul> 
                <div class="clearfix"></div> 
               </div> 
               <div class="x_content"> 
                <div class="dashboard-widget-content"> 
                 <table class="table" > 
                  <thead> 
                   <tr> 
                    <th>#</th> 
                    <th>Date</th> 
                    <th>Name</th> 
                    <th>Address</th> 
                    <th>Email</th> 
                    <th>Phone</th> 
                    <th>Institute Name</th> 
                    <th>Institute Head</th> 
                    <th>Product Name</th> 
                    <th>Message</th> 
                   </tr> 

                  </thead> 
                  <tbody> 
                   <?php 
                   $count = 1; 
                   $query = "select * from tbl_enquiry order by date desc limit 5"; 
                   $result = mysql_query($query)or die(mysql_error()); 
                   while($row = mysql_fetch_array($result)) 
                   { 
                   ?> 
                   <tr> 
                    <td><?php echo $count ?></td> 
                    <td><?php echo $row['date']; ?></td> 
                    <td><?php echo $row['name']; ?></td> 
                    <td><?php echo $row['address']; ?></td> 
                    <td><?php echo $row['email']; ?></td> 
                    <td><?php echo $row['phone']; ?></td> 
                    <td><?php echo $row['institute_name']; ?></td> 
                    <td><?php echo $row['institute_head']; ?></td> 
                    <td><?php echo $row['product']; ?></td> 
                    <td><?php echo $row['message']; ?></td> 
                   </tr> 
                   <?php 
                   $count += 1; 
                   } 
                   ?> 
                  </tbody> 
                 </table> 
                </div> 
                <div class="clearfix"></div>   
             <a href="enquiries.php" class="btn btn-primary btn-xs pull-right" >View All</a> 
               </div> 
              </div> 
             </div> 

            </div> 

           </div> 

          </div> 

          <?php 
          include "footer.php"; 
          ?> 
         </div> 
         <!-- /page content --> 

        </div> 

       </div> 

       <div id="custom_notifications" class="custom-notifications dsp_none"> 
        <ul class="list-unstyled notifications clearfix" data-tabbed_notifications="notif-group"></ul> 
        <div class="clearfix"></div> 
        <div id="notif-group" class="tabbed_notifications"></div> 
       </div> 

      <?php 
      include 'footer_links.php'; 
      ?> 
    </body> 

</html> 

回答

0

您应该设置HTTP响应代码302设置Location头通常是不够的。

而且,不存储密码的cookie,不存储在cookie的用户名,饼干应该是一个会话标识符,您可以用在服务器上查找该用户当前会话。 在cookie中存储密码不安全。

+0

请我detail.how我可以设置HTTP响应代码302的解决方案? –