2014-05-20 17 views
1

我想獲取從這個SQL表LANDING_PAGE值,並將其添加到文件頭位置正在提取文本值在頭部使用:位置

:Ive得到了下面的代碼在頁面的頂部,但這個給我一個空白頁:

<?php 
    foreach($[user_name] as $user) { 
    $location="Location:http://".$user['landing_page']; 
    header($location); 
} 
?> 

<!-- if you need user information, just put them into the $_SESSION variable and output them here --> 
Order: <?php echo $_SESSION['user_name']; ?>. You are securely logged in. 

我在哪裏出錯了?

enter image description here

enter image description here

原代碼是我試圖讓用戶去google.com登錄後

+0

如果您的landing_page爲http://如數據庫圖片所示爲什麼要在標頭(「位置」)中添加http://: –

+0

空白頁通常表示PHP錯誤。在頁面開始處添加'ini_set('display_errors',true);'開啓錯誤報告。另外,'$ user_name'對於那個變量來說似乎是一個奇怪的名字,並且foreach在這裏看起來也是錯誤的。 –

回答

1

你沒有正確附加變量登錄腳本。嘗試用,

header('"'.$user['landing_page'].'"); 
+0

數據庫中已經有一個http://。這會導致'Location:http:// http:// blah.com'。 –

+0

這仍然帶我到一個空白頁面,而不是一個URL錯誤。 – user3654802

+1

爲什麼你在foreach循環中嘗試它?如果查詢每次只返回一條記錄,則不要使用'foreach'循環。 – Jenz

1

我想你可以通過簡單地

header("Location: " . $user['landing_page']); 
0

附加參數在頭試試這個做到這一點:

<?php 
header("Location: ".$user['landing_page']); 
?> 
0

試試這個

<?php 
    foreach($user_name as $user) { 
     header("Location:http://".$user['landing_page']); 
    } 
?> 

<?php 
    foreach($user_name as $user) { 
     $location="Location:http://".$user['landing_page']; 
     header($location); 
    } 
?>