2012-04-09 96 views
1

我試圖使用註冊頁面中生成的用戶名和密碼哈希將數據發佈到登錄頁面。我有這個工作,但爲了我的生活無法弄清楚爲什麼它已經停止。PHP在註冊後將數據轉發到登錄頁面

基本上,如果註冊成功,代碼將重定向用戶以自動登錄。但是,該代碼也用於管理面板,因此可以添加用戶並將其返回到用戶管理屏幕。

if (isset($_GET['redirect'])){ 
     if (isset($_GET['login'])){ 
      if($_GET['login'] == "true"){ 
        // So we can log users automatically after registering 
       $post = http_build_query(
        array(
         "username" => $username, 
         "password" => $password 
        ) 
       ); 
       $context = stream_context_create(
        array(
         "http"=>array(
          "method" => "POST", 
          "header" => "Content-Type: application/x-www-form-urlencoded\r\n", 
          "content" => $post 
         ) 
        ) 
       ); 
       // testing shows that the code gets this far... 
       // but does not send the following... instead it skips this 


       $page = file_get_contents('http://example.com/login.php?redirect='.$_GET['redirect'], false, $context); 
      } 
     } 
     header('Location: ' . $_GET['redirect']); 

     echo('<p><a href="'.$_GET['redirect'] . '">Back to where you were...</a></p>'); 

    } 

回答

0

我認爲你必須提供只是密碼,而不是它的哈希碼。

或者(如果此時無法訪問普通密碼),則可以擴展登錄腳本。例如,它必須支持其他一些條件來記錄用戶在哪裏不需要明文密碼 - 它可以採用密碼的散列。或者將用戶標記爲登錄在單獨的可訪問位置的代碼,並在註冊後執行它,而無需轉到原始登錄頁面。

+0

感謝您使用密碼而不是哈希值。這是絕對正確的我的登錄腳本需要密碼而不是哈希。 但是,file_get_contents仍在跳過。 我要試一下,看看我是否可以讓用戶在註冊頁面內登錄...希望它有效。 – Panda 2012-04-09 06:09:57

+0

我剛剛創建了用戶會話,而不是嘗試將數據發送到登錄頁面。謝謝。 – Panda 2012-04-09 06:18:44