2016-11-11 44 views
0

我包括在我的註冊頁面我的PHPMailer和使用簡單的Ajax推送數據與數據庫進行交互......一切工作在我的本地罰款,但是當我上傳到服務器,我得到這個內部錯誤500 HTML的PHPMailer導致內部錯誤500與阿賈克斯

<script> 
$(document).ready(function(){ 
    $("#register-btn").click(function(){ 

     var name=$("#hostel-name").val(); 
     var email=$("#email").val(); 
     var conf_email=$("#conf-email").val(); 
     var password=$("#password").val(); 


     $.ajax({ 
      url:"functions/register.php", 
      data:{ 
       name:name, 
       email:email, 
       conf_email:conf_email, 
       password:password 
       }, 
      type:"POST", 
      success:function(data){ 
       $("#result").html(data); 
      } 
     }); 
    }); 
    }); 

</script> 
<section id="result"> 

</section> 

<section class="row"> 
    <section class="container"> 
     <section class="col-md-offset-4 col-md-4" id="register"> 
     <h1 class="title text-center" style="border-left:0;margin-top: -10px;"><a href="index">Accomonde</a></h1> 
      <h3 class="title">Sign Up</h3> 
      <br> 

       <section class="form-group col-md-12"> 
       <label> Name</label> 
       <input type="text" class="form-control" name="hostel-name" id="hostel-name" autocomplete="off" placeholder="Hostel Name" required> 
       </section> 

       <section class="form-group col-md-12"> 
       <label>Email</label> 
       <input type="email" class="form-control" name="email" id="email" autocomplete="off" placeholder="Your Email" required> 
       </section> 

       <section class="form-group col-md-12"> 
       <label>Confirm Email</label> 
       <input type="email" class="form-control" name="conf-email" id="conf-email" autocomplete="off" placeholder="Confirm Your Email" required> 
       </section> 

       <section class="form-group col-md-12"> 
       <label>Password</label> 
       <input type="password" class="form-control" name="password" id="password" autocomplete="off" placeholder="Your Password" required> 
       <br> 
       <section class="form-group"> 
        <button class="form-control btn-primary" name="register" id="register-btn" ><span class="fa fa-paper-plane"> Sign Up</span></button> 
       </section> 
       <section class="form-group"> 
        <ul class="list-inline"> 
         <li class="pull-left">Already Have an Account?</li> 
         <li class="pull-right"><a href="login">Log in!</a> </li> 
        </ul> 
       </section> 

     </section> 
    </section> 
</section> 

```

,這是我的PHP腳本

<?php 
    require_once '../libs/phpmailer/PHPMailerAUtoload.php'; 
    try{ 
     include '../database/connection.php'; 
     $hostel_name=$_POST['name']; 
     $email=filter_var($_POST['email'],FILTER_VALIDATE_EMAIL); 
     $password=hash('sha256',$_POST["password"]); 
     $confemail=filter_var($_POST['conf_email'],FILTER_VALIDATE_EMAIL); 
     $confirm_code=md5(uniqid(rand())); 
     $user_id=md5(rand(0,10000)); 
     //new block added 
      if($name="" or $email=="" || $password=="" || $confemail=="" ){echo '<p class="alert alert-danger text-center">Please Make Sure All Fields Are Filled <span class="close pull-right"><span class="close pull-right"> <a href="#" >&times;</a></span></p>';} 

      elseif($email==$confemail){ 
     $query=$dbc->query("select * from users where email='$email'"); 


    if($result=$query->fetch(PDO::FETCH_NUM)==1){ echo ' 
    <p class="alert alert-danger text-center">We already have someone with that email <span class="close pull-right"><span class="close pull-right"> <a href="#" >&times;</a></span></p>'; }elseif($result=$query->fetch(PDO::FETCH_NUM)==0){ 
     $data_result=$dbc->query("insert into users(hostel_name,email,password,confirm_code,user_id) values('$hostel_name','$email','$password','$confirm_code','$user_id')"); 
    if($data_result){ 
      $m = new PHPMailer; 
     $m ->isSMTP(); 
     $m->SMTPAuth=true; 

     // debugging 
     // $m->SMTODebug=1 
     // endof debug 
     $m->Host="smtp.gmail.com"; 
     $m->Username="[email protected]"; 
     $m->Password="lollypop28:)"; 
     $m->SMTPSecure='ssl'; 
     $m->Port=465; 
     $m->isHtml(true); 

     $m->Subject = 'Welcome to Efie'; 
     ob_start(); 
include '../views/email/register-email.php'; 
$body = ob_get_contents(); 

    $m->msgHTML($body, dirname(__FILE__)); 
     $m->FromName="Efie Ghana"; 
     $m->AddAddress($email,$hostel_name); 
     ob_end_clean(); 
     $m->send(); 

     echo '<p class="alert alert-success text-center error-message"> You\'re almost there! Check your inbox to activate your account.</p>'; 

     } 

    } 
} 
}catch(Exception $e){echo '<p class="alert alert-danger text-center error-message">Something is not right <span class="pull-right close"> <a href="#" >&times;</a></span></p>';} 

$dbc=null; 





?> 

```

+2

請不要__roll你自己的密碼散列。 PHP提供['password_hash()'](http://php.net/manual/en/function.password-hash.php) 和['password_verify()'](http://php.net/manual/ en/function.password-verify.php)請使用它們。 這裏有一些[有關密碼的好點子(https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) 如果您使用的是PHP版本5.5之前的[有可以在這裏找到一個兼容包(HTTPS ://github.com/ircmaxell/password_compat) – RiggsFolly

+1

不要生成自己的'$ USER_ID = MD5(蘭特(0,10000));'做'欄自動increment'代替 – RiggsFolly

+0

檢查服務器日誌以查找原因500錯誤。如果我不得不猜測,我會說你的本地主機上的數據庫連接或PHPMailerAUtoload的相對路徑是正確的,但不在服務器上。 – bassxzero

回答

1

Linux文件系統通常是大小寫敏感的,所以這是行不通的:

require_once '../libs/phpmailer/PHPMailerAUtoload.php'; 

應該是:

require_once '../libs/phpmailer/PHPMailerAutoload.php'; 

在一般情況下,你會得到一個錯誤500的任何時間,你可以找到更多詳細瞭解您的Web服務器日誌文件中的錯誤。

而且你的腳本是容易受到SQL注入 - 當你檢查的電子郵件地址是有效的,它可能有一個字符串就是這樣也是一個有效的SQL注入攻擊一個有效的電子郵件地址。總是逃避你放入SQL的東西。