2014-01-15 56 views
0

//顯示的是當我RegistrationPage.php以下消息寄存器過程頁:不能更改頭信息 - 頭已經在瀏覽器中發送的消息

Warning: Cannot modify header information - headers already sent by (output started at /home/cs12jkk/public_html/validation.inc:4) in /home/cs12jkk/public_html/register-process.php on line 67 

//這裏是67行的代碼:

//final disposition 
if (count($_SESSION['error']) > 0) { 
    die (header("Location: RegistrationPage.php")); 
} else { 
    if(registerUser($_POST)) { 
     unset($_SESSION['formAttempt']); 
     die(header("Location: success.php")); 
} else { 
error_log("Problem registering user: {$_POST['email']}"); 
     $_SESSION['error'][] = "Problem registering account"; 
     die(header("Location: RegistrationPage.php")); 
    } 
} 

//這是我validation.inc代碼:

<?php 

function is_valid_($county) { 
    $validCounties = array ("Avon","Bedfordshire","Berkshire","Borders","Buckinghamshire","Cambridgeshire","Central","Cheshire","Cleveland","Clwyd","Cornwall","County Antrim","County Armagh","County Down","County Fermanagh","County Londonderry","County Tyrone","Cumbria","Derbyshire","Devon","Dorset","Dumfries and Galloway","Durham","Dyfed","East Sussex","Essex","Fife","Gloucestershire","Grampian","Greater Manchester","Gwent","Gwynedd County","Hampshire","Herefordshire","Hertfordshire","Highlands and Islands","Humberside","Isle of Wight","Kent","Lancashire","Leicestershire","Lincolnshire","Lothian","Merseyside","Mid Glamorgan","Norfolk","North Yorkshire","Northamptonshire","Northumberland","Nottinghamshire","Oxfordshire","Powys","Rutland","Shropshire","Somerset","South Glamorgan","South Yorkshire","Staffordshire","Strathclyde","Suffolk","Surrey","Teesside","Tyne and Wear","Warwickshire","West Glamorgan","West Midlands","West Sussex","West Yorkshire","Wiltshire","Worcestershire",); 
    if (in_array($county,$validCounties)) { 
      return true; 
    } else { 
      return false; 
    } 
} //end function is_valid_county 

function is_valid_postcode($postcode) { 
     if (preg_match('/^[\d]+$/',$postcode)) { 
       return true; 
     } else if (strlen($postcode) == 5 || strlen($postcode) == 9) { 
       return true; 
     } else { 
       return false; 
     } 
} //end function is_valid_postcode 

?> 

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Untitled Document</title> 
</head> 

<body> 
</body> 
</html> 

//任何想法,我在做什麼錯?

+0

答案是錯誤消息,你的問題是在'第4行validation.inc'作爲輸出開始出現,而不是在你發佈的代碼。例如,請參閱:http://stackoverflow.com/questions/1912029/warning-cannot-modify-header-information-headers-already-sent-by-error – jeroen

+0

但validation.inc中的第4行只是<?php – user3196072

+0

所以你必須在此之前,3行輸出... – jeroen

回答

2

應該是

header("Location: RegistrationPage.php"); 
exit;// or die(); 

代替

die (header("Location: RegistrationPage.php")); 
+0

這會如何改變? – jeroen

+0

我試過這個,同樣的錯誤信息仍然顯示!謝謝 – user3196072

+0

@ user3196072,正如jeroen提到的。刪除你的'validation.inc'中的3個空白行 –

0

die()是輸出的一部分。

因爲header();會立刻跳轉,你可以叫你die();後重定向。

拆分您的通話中:

header("Location: yourfile.php"); 
die(); 
相關問題