PDA

View Full Version : php header warning help please



Moshambi
08-28-2008, 10:35 PM
Warning: Cannot modify header information - headers already sent by (output started at D:\XAMPP\xampp\htdocs\freshandfunky\logout.php:3) in D:\XAMPP\xampp\htdocs\freshandfunky\logout.php on line 8

this is my file:



<?php session_start(); ?>

<?php
echo "You are now logged out, " . $_SESSION['user'] . ". <br /> We'll see you next time!";

$_SESSION['loggedIn'] = "false";

header("Location: index.php");

?>


thanks for any help

Nile
08-28-2008, 10:48 PM
Take a look at ob_start:
http://us2.php.net/ob_start
Also make sure that your code in the head part of the document.

magicyte
08-29-2008, 02:35 AM
Nile, is it possible to display time in the title of the HTML page with PHP?

-magicyte

Moshambi
08-29-2008, 04:26 AM
Cool thanks nile i read up a little on that link you posted then did a little research on headers and i got it working exactly how i want it now. thanks for the help!

codeexploiter
08-29-2008, 04:55 AM
Nile, is it possible to display time in the title of the HTML page with PHP?

-magicyte



<?php
$time = date("h:i:s A");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title><?php print "Current Time is {$time}"; ?></title>
<style type="text/css">

</style>
<script type="text/javascript">

</script>
</head>
<body>
<div>Setting the Page Title using PHP</div>
</body>
</html>

Twey
08-29-2008, 03:47 PM
http://dynamicdrive.com/forums/showpost.php?p=158839&postcount=1337 — 4.1, 4.2. Solving 4.1 will fix your problem. Output buffering is overkill in this particular instance.

You are not allowed to change the headers after sending output, due to the way HTTP data is structured.

Moshambi
08-29-2008, 05:41 PM
ok i changed my code to this and works fine now:



<?php
session_start();
header("location: index.php");

$_SESSION['loggedIn'] = "false";

?>


do you think i should just session_destroy() instead of setting the login to false? would it be safer?