2013-09-23 136 views
-5

我創建了一個網站,用php和SQL使用WampServer。 在條件或boucle後,我使用標題位置將用戶轉移到另一個頁面。但我從服務器得到一個錯誤,我認爲是因爲我在代碼之後使用頭,而不是。我刪除了所有空格。標題位置問題,如何解決?

if($passfinal['contrasena']==$_POST['password']) 
{ 
$_SESSION['logedin']=TRUE; 
$_SESSION['userid']=$passfinal['id']; 
header('Location: ../index.php'); 
} 

你有什麼可以幫助我嗎? Thnak你。

+1

在'header(...)'之後放置'exit;'。你會得到哪個錯誤信息? – djot

+0

檢查錯誤文件找到問題, 它可能是一個錯誤,或者你輸出一些數據。 – mbouzahir

+0

問題仍然存在。我得到這個錯誤:警告:無法修改標題信息 -/home/sirobdco/public_html/login/includes/loginform/loginform中已發送的標題(輸出開始於/home/sirobdco/public_html/login/login.php:11) .php在線37 –

回答

0

我認爲,這裏是問題$_POST['password'],因爲你做比較之前,首先你必須檢查if(isset($_POST['password'])),空格是不是在這種情況下和最後一個很重要的:我勸你,你必須寫在標題功能完整的URL ,像這樣:header('location: http://example.com/index.php'),因爲這是更好,更真實的方式。

+0

謝謝,但我檢查之前是$ _POST ['password']。讓我看看改變位置。 –

+0

這是一段和平的代碼,我不能只使用這段代碼,你能告訴我們完整的代碼,還是更多? – dasdasdasdasd

+0

好吧,我會編輯我的問題,謝謝 –

0

Warning: Cannot modify header information - headers already sent by (output started at /home/sirobdco/public_html/login/login.php:11) in /home/sirobdco/public_html/login/includes/loginform/loginform.php on line 37

您已經發送了標題,以便PHP不能再發送它們!
也就是說,你的代碼之前

header('Location: ../index.php'); 

您已經發送標題 - 在HTML空白,在PHP回聲等

有通過這個閱讀:
http://php.net/manual/en/function.header.php

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.