2016-05-17 140 views
-2

我在我们的web服务器上部署web应用程序时遇到了一个错误,该应用程序在localhost上完美运行。 这里是我启动登录页面时显示的内容。php html服务器部署

login($_POST['email'], $_POST['password']); $email=$_POST['email']; $_SESSION["email"] = "$email"; } ?> 

这里是我的login.php源

<?php 
session_start(); 
if (isset($_POST['login'])) 
    { 
    include_once 'user-dbop.php'; 
    $objUser = new User(); 
    $objUser->login($_POST['email'], $_POST['password']); 

    $email=$_POST['email']; 
    $_SESSION["email"] = "$email"; 

    } 
?> 

<html> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
     <meta name="description" content=""> 
     <meta name="author" content=""> 
     <link rel="icon" href="../../favicon.ico"> 

     <title>connexion </title> 
     <!-- Bootstrap core CSS --> 
     <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
     <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
     <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
     <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> 

     <link rel="stylesheet" href="https://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css"> 
     <!--<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>--> 
     <link href='https://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'> 
     <style> 
      .at_background{ 
       background: url(back2.jpg) no-repeat center center fixed; 
       -webkit-background-size: cover; 
       -moz-background-size: cover; 
       -o-background-size: cover; 
       background-size: cover; 
      } 
      .at_font{ 
       color: navy; 
       /*font-family: 'Indie Flower', cursive;*/ 
       font-family: 'Lobster', cursive; 
      } 
     </style> 


<style type="text/css"> 

body { 

    /**scalable background to fill available viewport**/ 
    background: url(img/bleu.jpg) center center fixed; 

    -webkit-background-size: cover; 
    -moz-background-size: cover; 
    -o-background-size: cover; 
    background-size: cover; 
} 

</style> 



<body> 


<div class="container"> 

<div style=" margin-top: 5px" class="well well-sm"> 
    <h1 style="color: white"><img src="img/mobilis-edd.png" class="img-rounded pull-xs-left" width="150" height="55"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <mark style="background-color:rgb(224,224,224) ">Gestion des demandes de récupirations</mark></h1>  
    </div> 

<nav class="navbar navbar-inverse" style="background-color: #505050 ;"> 
    <div class="container-fluid"> 

     <div class="navbar-header"> 
     <a class="glyphicon glyphicon-home navbar-brand" href="index.php"></a> 
     </div> 



    </div> 
    </nav> 
    <div class="row well well-lg "> 

        <div > 
           <div class="jumbotron "> 
            <h2 > Veuillez vous connecter !</h2> 

         <hr> 
          <form action="" method="post"> 
           <div class="form-group"> 
            <label for="email">Email:</label> 
            <input type="email" class="form-control" id="email" placeholder="Enter email" name="email" required> 
           </div> 
           <div class="form-group"> 
            <label for="pwd">Password:</label> 
            <input type="password" class="form-control" id="pwd" placeholder="Enter password" name="password"> 
           </div> 

           <button type="submit" class="btn btn-primary" name="login">Connecter</button> 

          </form> 
         </div> 
        </div> 

       </div> 


     <div style="background-color: rgb(81,80,82)" class="panel-footer panel-custom"> 
     <p style="color: #ffffff;" class="text-center">Equipe developement WEB DSI [email protected]</b> 
     </div> 

</div> 

</body> 

</html> 

和我的用户drop.php所有功能

<html> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
     <meta name="description" content=""> 
     <meta name="author" content=""> 
     <link rel="icon" href="../../favicon.ico"> 

     <title>fonction</title> 
     <!-- Bootstrap core CSS --> 
     <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
     <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
     <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
     <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"> 
     <link rel="stylesheet" href="https://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css"> 
     <!--<link href='https://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>--> 
     <link href='https://fonts.googleapis.com/css?family=Indie+Flower' rel='stylesheet' type='text/css'> 
<?php 

if (!isset($_SESSION)) 
session_start();  
include_once 'config.php'; 

class User { 

    var $dbObj; 

    public function __construct() { 
     $this->dbObj = new db(); 
    } 

    public function insert($password, $name, $address, $contact_no, $about, $email, $affectation) { 
     $password = hash('sha256', $password); 
     $sql = " INSERT INTO `user`" 
       . " (`password`,`name`,`address`,`contact_no`,`about`,`email`,`affectation`,`user_id`)" 
       . " VALUES('$password','$name','$address','$contact_no','$about','$email','$affectation','')"; 
       echo $sql; 
     return $this->dbObj->ExecuteQuery($sql, 2); 
    } 

    public function update( $password, $name, $address, $contact_no, $about, $old_password, $email, $user_id) { 
     if (empty($password)) 
      $password = $old_password; 
     else 
      $password = hash('sha256', $password); 
     $sql = " UPDATE" 
       . " user " 
       . " SET password = '$password',name = '$name',address = '$address'," 
       . " contact_no = '$contact_no',about = '$about', email = '$email'" 
       . " WHERE user_id = '$user_id'"; 
     return $this->dbObj->ExecuteQuery($sql, 3); 
    } 

    public function select_by_id($user_id) { 
     $sql = " SELECT" 
       . " user_id,user_name,password,name,address,contact_no,about,email" 
       . " FROM user WHERE user_id = '$user_id'"; 
     return $this->dbObj->ExecuteQuery($sql, 1); 
    } 

    public function delete_account($user_id) { 
     $sql = " DELETE FROM user WHERE user_id = '$user_id'"; 
     return $this->dbObj->ExecuteQuery($sql, 3); 
    } 

    public function login($email, $password) { 
     $password = hash('sha256', $password); 
     $sql = " SELECT" 
       . " name, email" 
       . " FROM user WHERE" 
       . " email = '$email' AND password = '$password'"; 
     $data = $this->dbObj->ExecuteQuery($sql, 1); 
     if (mysqli_num_rows($data) > 0) { 
      $fetch_data = mysqli_fetch_assoc($data); 
      $_SESSION['user_id'] = $fetch_data['user_id']; 
      $_SESSION['name'] = $fetch_data['name']; 
      echo "<SCRIPT>alert(\"marquer sont message\");</SCRIPT>"; 
      header("location:list.php"); 
      } 
      else { 
      echo "<script > 
      window.location='login.php'; 
      alert('Invalid User Name or Password !!'); 
      </script>"; 

     } 
    } 

} 

?> 
</html> 
+2

这是什么问题? – Epodax

+0

用'session_start()'替换'if(!isset($ _ SESSION))session_start()'' – Justinas

+0

你对此有何疑问? –

回答

0

这里有几件事情错在这里:

  • 正如注释中所述,您在会话检查时遇到问题。但是如果你的班级文件结构更好,你根本不需要检查会话。
  • 您的user-drop.php文件应该只包含定义该类的PHP代码,并且不包含HTML。它也不需要检查会话。你使用它的唯一地方是在登录过程中,但它应该真的返回一个用户对象,你可以在login.php中的调用代码中设置会话值。
  • 你的本地主机和生产环境之间可能有不同的错误设置,这就是为什么你有不同的行为(你的代码是错误的,所以它可能无法在开发中“完美”工作,或者你只是没有看到错误) 。
  • 您的登录功能试图在处理时直接插入脚本标签。让类返回错误代码或抛出异常并对调用函数中的异常做出反应是一种更好的设计。