ericburnard Posted December 29, 2007 Share Posted December 29, 2007 Hey i have read the header stick looked it up on numerous websites but i am still confussed about why i get this error Warning: Cannot modify header information - headers already sent by (output started at /home/www/ericburnard.freehostia.com/index2.php:1) in /home/www/ericburnard.freehostia.com/header.html on line 2 Warning: Cannot modify header information - headers already sent by (output started at /home/www/ericburnard.freehostia.com/index2.php:1) in /home/www/ericburnard.freehostia.com/header.html on line 3 Warning: Cannot modify header information - headers already sent by (output started at /home/www/ericburnard.freehostia.com/index2.php:1) in /home/www/ericburnard.freehostia.com/header.html on line 4 This is the code i am using. <?php // Date in the past header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Pragma: no-cache"); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="style.css" rel="stylesheet" type="text/css" /> <title>.: Eric's Blog :.</title> <? $p = $_GET['p']; if ($p == 'home') { echo "This is the home file"; } else if ($p == 'login') { header('Location:www.login.com'); } else if ($p == 'photos') { echo "This is the photos file"; } else if ($p == 'wall') { echo "This is the wall file"; } else if ($p == 'links') { echo "This is the links file"; } else if ($p == 'contact') { echo "This is the contact file"; } else { echo "No page with that ID exists."; } ?> </head> <body> <div style="position: Absolute; left: 140px; top: 70px; height: 10px; width: 10px; padding: 1em; z-index: 1"> <form name="input" action="login.php" method="get"> Username: <input type="text" name="username" class="text"width="20"><BR> Password: <input type="password" name="password" class="text" width="20"><br><br> <input type="submit" value="Submit" class="submit"> </form> </div> <div id="container"> <div id="header"> <ul> <li><a href="?p=home">Home</a></li> <li><a href="?p=login">Login</a></li> <li><a href="?p=photos">Photos</a></li> <li><a href="?p=wall">Wall</a></li> <li><a href="?p=links">Links</a></li> <li><a href="?p=contact">Contact</a></li> </ul> </div> <br><br> <div id="footer"></div> Any help would be great Eric x Quote Link to comment https://forums.phpfreaks.com/topic/83581-header/ Share on other sites More sharing options...
nuxy Posted December 29, 2007 Share Posted December 29, 2007 Lazy way: Add ob_start(). You are most probably including this script somewhere, you need to remove "all" data echo/prinited becausea header is sent. Quote Link to comment https://forums.phpfreaks.com/topic/83581-header/#findComment-425219 Share on other sites More sharing options...
teng84 Posted December 29, 2007 Share Posted December 29, 2007 just put your php script on top of you html you you wont get that message and ad an exit after you declare header in your if statement Quote Link to comment https://forums.phpfreaks.com/topic/83581-header/#findComment-425230 Share on other sites More sharing options...
PHP_PhREEEk Posted December 29, 2007 Share Posted December 29, 2007 If you read the sticky, you didn't 'get' it at all... Your script sends out actual headers, then you check $_GET['p'], and if it equal login, you call header(). You can't do that, because you've already sent the header. PHP does not like to start sending a part of a page, then stop and start sending something different. Your browser wouldn't be amused either... PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/83581-header/#findComment-425245 Share on other sites More sharing options...
PFMaBiSmAd Posted December 29, 2007 Share Posted December 29, 2007 There are actually two problems. The first one is what is causing the error messages (output started in line 1) and is what is preventing the three headers in lines 2,3, and 4 from working. The second problem is the use of a header('Location:...') redirect after the file outputs html content. For the first problem, here is the short answer - either your file contains some white space (one or more spaces, tabs, or newlines) before the opening <?php tag or the file is saved in UTF-8 format and the BOM (byte order marker) characters at the start of the file are being output to the browser. Either white space or the BOM characters are "content" that is output to the browser and are preventing headers from being sent. Putting ob_start() in your script will not correct this problem. You could turn on output buffering in php.ini or a .htaccess file to work around this problem, but fixing your file is the correct way to solve this problem. For the second problem, do what the sticky post and teng84 suggests and put any php logic that determines if a redirect will occur on the page first, before the file outputs any content to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/83581-header/#findComment-425273 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.