2016-04-27 85 views
0

因此,我有一個網站使用註冊/登錄系統爲用戶創建一個帳戶。我使用MAMP在本地主機上完美工作。但是,我將我的網站和數據庫上傳到實時服務器,並且出現錯誤。以下是註冊頁面。當用戶登記,就應該帶他們到他們的帳戶頁面,但是在註冊頁面刷新,他們得到以下錯誤:活網站上的PHP錯誤,在本地主機上正常工作

警告:在session_start():無法發送會話cookie - 標題已經發出(輸出開始於/srv/disk4/2113278/www/lucasclarke.co.nf/webTechFinal/connections.php:16)位於第7行的/srv/disk4/2113278/www/lucasclarke.co.nf/webTechFinal/Register.php

警告:在session_start():無法發送會話緩存限制器 - 在已經發送了頭(輸出開始/srv/disk4/2113278/www/lucasclarke.co.nf/webTechFinal/connections.php:16)/ SRV /磁盤4/2113278/WWW/lucasclarke.co.nf/webTechFinal/Register.php線路7

警告:不能更改頭信息 - 頭已經發出(輸出開始/ SRV /磁盤4/2113278/WWW/lucasclarke。 co.nf/webTechFinal/connections.php:16)在/srv/disk4/2113278/www/lucasclarke.co.nf/webTechFinal/Register.php第16行

注意,信息用戶寄存器DOES正確地進入我的數據庫,但該網站沒有像我在本地主機上那樣工作。有什麼想法嗎?提前致謝。

<?php require 'connections.php'; ?> 

<?php 

    if(isset($_POST['register'])) { 

     session_start(); 

     $fname = $_POST['first_name']; 
     $lname = $_POST['last_name']; 
     $email = $_POST['email']; 
     $pw = $_POST['password']; 

     $sql = $con->query("INSERT INTO user (Fname, Lname, Email, Password)Values('{$fname}', '{$lname}', '{$email}', '{$pw}')"); 

     header('Location: Login.php'); 
     } 
?> 

<!------------------------------------------------------------------> 

<!DOCTYPE HTML> 
<html lang="en"> 
    <head> 
     <title>Notekeep</title> 
     <link rel="stylesheet" type="text/css" href="stylesheet.css"> 
    </head> 

    <body> 

      <div class="container"> 

       <h1 class="title">Register<img src="logo.png" id="logo"></h1> 

      <form action="" method="post" name="registerform" id="registerform"> 
       <div> 
        <input name="first_name" type="text" required="required" id="first_name" placeholder="First Name"> 
       </div> 
       <div> 
        <input name="last_name" type="text" required="required" id="last_name" placeholder="Last Name"> 
       </div> 
       <div> 
        <input name="email" type="email" required="required" id="email" placeholder="Email"> 
       </div> 
       <div> 
        <input name="password" type="password" required="required" id="password" placeholder="Password"> 
       </div> 
       <div> 
       <!-- <input name="password2" type="password" required="required" id="password2" placeholder="Re-Enter Password"> --> 
       </div> 
      <div> 
        <input name="register" type="submit" class="button" id="register" value="Register"> 
       </div> 
      </form> 

      <a class="link" href="Login.php">Login</a> 

      </div> 
    </body> 

</html> 
+1

檢查connections.php的第16行 – Musa

+0

'<?php require'connections.php'後面的空格; ''不能在那裏。服務器將該空間計數爲輸出到引發錯誤的瀏覽器。刪除'?>'和<?php' – Rasclatt

+0

你也應該在'header('Location:Login.php');'後面添加'exit;'。 – Rasclatt

回答

0

正如我在我的評論中提到,你的頭應該是這樣的:

<?php 
require('connections.php'); 
// Remove space, should be continuous 
// I would personally start session here 
session_start(); 
if(isset($_POST['register'])) { 
    $fname = $_POST['first_name']; 
    $lname = $_POST['last_name']; 
    $email = $_POST['email']; 
    $pw = $_POST['password']; 

    // !! This is injection-prone !! 
    // You need to use bind parameters, this is unsafe 
    $sql = $con->query("INSERT INTO user (Fname, Lname, Email, Password)Values('{$fname}', '{$lname}', '{$email}', '{$pw}')"); 

    header('Location: Login.php'); 
    // Add here so the script stops execution 
    exit; 
} 
?> 

而且,請注意SQL注入,你是容易的。您應該使用參數綁定:

function insertNewUser($array,$con) 
    { 
     foreach($array as $key => $value) { 
      $key    = trim($key,':'); 
      $new[":{$key}"] = $value; 
     } 
     // I am assuming the use of PDO 
     $query = $con->prepare("INSERT INTO `user` (`Fname`,`Lname`,`Email`,`Password`) VALUES (:0,:1,:2,:3)"); 
     $query->execute($new); 
    } 

用途:

$data = array(
       $_POST['first_name'], 
       $_POST['last_name'], 
       $_POST['email'], 
       $_POST['password'] 
      ); 

// Use the function 
insertNewUser($data,$con); 

header('Location: Login.php'); 
exit; 

最後,你不應該將明文口令到你的數據庫。您應該使用password_hash()password_verify()(或兼容庫)

相關問題