2014-01-28 177 views
0

有人從wikihow使用此script來自wikihow的安全登錄腳本

默認情況下,無論是在登錄和註冊頁面您重定向到「protected_pa​​ge.php」受保護的頁面應該驗證與您的登錄:`

<?php 

include_once 'includes/db_connect.php'; 
include_once 'includes/functions.php'; 

sec_session_start(); 
?> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset="UTF-8"> 
     <title>Secure Login: Protected Page</title> 
     <link rel="stylesheet" href="styles/main.css" /> 
    </head> 
    <body> 
     <?php if (login_check($mysqli) == true) : ?> 
     <p>Welcome <?php echo htmlentities($_SESSION['username']); ?>!</p> 
      <p> 

<?php else : ?> 
      <p> 
       <span class="error">You are not authorized to access this page.</span> Please <a href="index.php">login</a>. 
      </p> 
     <?php endif; ?> 

問題是我總是得到錯誤消息,即使我的數據庫配置和註冊信息發送到數據庫,我甚至編輯了註冊表單添加更多的信息沒有任何問題在數據庫端,但我仍然總是得到這個錯誤msg當試圖登錄該網站時。有人有這個問題嗎?

+0

請問您能告訴我們您收到了哪些錯誤信息嗎? –

+0

「您無權訪問此頁面」 – user3144965

+0

您確定名稱和密碼是corect?嘗試在HTML下面打印'$ _SESSION'。像這樣:'

'。對POST也做同樣的事情,看看是否正在發送登錄細節。 –

回答

2

我有同樣的問題,並找到解決方案。我的問題是在我的php.ini文件中。

我不得不改變

session.save_path = "/var/php_sessions"

到:

session.save_path = "THE_DOCUMENT_ROOT_FOLDER_FROM_MY_HOST"

好運

0

我沒有答案,但我知道,這個問題必須在sec_session_start功能中找到: 如果你不使用$session_name = 'sec_session_id'session_name($session_name);session_regenerate_id(true); 代碼工作。

function sec_session_start() { 

// $session_name = 'sec_session_id'; // Set a custom session name 

    /*Sets the session name. 
    *This must come before session_set_cookie_params due to an undocumented bug/feature in PHP. 
    */ 

// session_name($session_name); 

    $secure = true; 
    // This stops JavaScript being able to access the session id. 
    $httponly = true; 
    // Forces sessions to only use cookies. 
    if (ini_set('session.use_only_cookies', 1) === FALSE) { 
     header("Location: ../error.php?err=Could not initiate a safe session (ini_set)"); 
     exit(); 
    } 
    // Gets current cookies params. 
    $cookieParams = session_get_cookie_params(); 
    session_set_cookie_params($cookieParams["lifetime"], 
      $cookieParams["path"], 
      $cookieParams["domain"], 
      $secure, 
      $httponly); 

    session_start();   // Start the PHP session 
// session_regenerate_id(true); // regenerated the session, delete the old one. 

}