duanbo1659 2014-05-18 15:55
浏览 28

将CSS和JS应用到代码后,PhP登录重定向停止工作

I am trying to write a simple login code. The problem is that the code works and redirects to dashboard.php without any css and js files. But as soon as include my header file,consisting of css and js, it stops working and gets stuck on auth_check.php. Here is my code.

main index file ( index.php) - containing the login form

 <?php include('header.php');?>
 <?php

 $message = $_GET['message'];
 if($message == 1) {
    echo '
    <div class="alert alert-success">
      <button type="button" class="close" data-dismiss="alert">
           Invalid username or password.</br> &times;</button>

    </div>
    ';

    }   
     if($message == 2) {
    echo '
    <div class="alert alert-success">
      <button type="button" class="close" data-dismiss="alert">
             You have successfully logged out! </br> &times;</button>

    </div>
    ';

    }
         ?>



         <div data-role="content">

     <div id="loginform" > //Login form code

      <form action="auth_check.php" method="post"> // form action="auth_check.php"
   <div id="usernameDiv" data-role="field-contain">
    <input type="text" id="name" name="username" placeholder="Username">
  </div>
  <div id="passwordDiv" data-role="field-contain">
    <input type="password" id="password" name="password"  placeholder="Password">
  </div>
  <div id="loginbuttonDiv" data-role="field-contain">
    <button type="submit" name="submit" id="loginbutton"></button>
 </div>

 </form>
 </div> 

<?php include('footer.php'); ?>

Authorisation check (auth_check.php) (here the header(location:) doesnt work after applying js in index.php :(

  <?php
  include('config.php');
 session_start();

 include 'PasswordHash.php';

 $hasher = new PasswordHash(8, FALSE);

 if (!empty($_POST))
 { 
   $username = $sql->real_escape_string($_POST['username']);


   $query = "SELECT id, password, UNIX_TIMESTAMP(created) AS salt
          FROM users
          WHERE username = '{$username}'";
  $user = $sql->query($query)->fetch_object();
    if ($user && $user->password == $hasher->CheckPassword($_POST['password'],  
        $user->password))
 {   

    session_register("username"); // session checker for pages
    $_SESSION['username']= $username; // storing username in session
    header("location: dashboard.php");
    exit;

  }
 else
  { 
     header("location: index.php?message=1");
     exit;
  }
}


?>

here is the file header.php which is causing the problem.

   <?php
  include('config.php');

   ?>
  <!DOCTYPE HTML>
  <html lang="en">

  <head>
  <meta charset="utf-8">

   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">


  <link rel="stylesheet" type="text/css" href="custom.css">
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-
   1.4.2.min.css" />
 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
  <script type="text/javascript" src="js/login.js"></script>


  <head>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ogg dd trandata 报错
    • ¥15 高缺失率数据如何选择填充方式
    • ¥50 potsgresql15备份问题
    • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
    • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
    • ¥60 pb数据库修改与连接
    • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
    • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
    • ¥20 神经网络Sequential name=sequential, built=False
    • ¥16 Qphython 用xlrd读取excel报错