0

//The register-process page is displaying the following message when my 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

//Here is the code on line 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"));
    }
} 

//this is my validation.inc code:

<?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>

//any idea what I'm doing wrong?

user3196072
  • 5
  • 1
  • 5
  • The answer is in the error message, your problem is in `validation.inc` on line 4 as the output started there, not in the code you posted. See for example: http://stackoverflow.com/questions/1912029/warning-cannot-modify-header-information-headers-already-sent-by-error – jeroen Jan 15 '14 at 13:40
  • but line 4 in validation.inc is just php – user3196072 Jan 15 '14 at 13:43
  • So you have 3 lines of output before that... – jeroen Jan 15 '14 at 13:44
  • i've changed it but it doesn't make a difference – user3196072 Jan 15 '14 at 14:22
  • Why are you outputting html (an empty page...) in your `validation.inc` script? If this is included before the shown code on `RegistrationPage.php`, that is your problem. – jeroen Jan 15 '14 at 18:31

2 Answers2

2

Should be

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

instead of

die (header("Location: RegistrationPage.php"));
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • How would that make a difference? – jeroen Jan 15 '14 at 13:45
  • i've tried this and the same error message is still displayed! Thanks though – user3196072 Jan 15 '14 at 13:49
  • @user3196072, As jeroen mentioned. Remove the 3 blank lines from your `validation.inc` – Shankar Narayana Damodaran Jan 15 '14 at 13:50
  • I have it still says this 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 – user3196072 Jan 15 '14 at 13:52
  • my login system can be viewed on my server at cs12jkk.icsnewmedia.net then clicking on RegistrationPage.php – user3196072 Jan 15 '14 at 13:53
  • @ShankarDamodaran You should modify your answer as it gets upvoted (why?) and it's wrong: The `header()` call gets executed before the `die()` call, so even if `die()` would produce output, it would still be **after** the call to the `header` function. And the error message clearly states where the problem is... – jeroen Jan 15 '14 at 13:58
0

die() is a part of output.

Because header(); will redirect you immediatly, you can just call die(); after your redirect.

Split your calls in:

header("Location: yourfile.php");
die();
Maarkoize
  • 2,601
  • 2
  • 16
  • 34