Ask about general coding issues or problems here.
Moderators: macek, egami, gesf
by cooldownguy86 » Sun Nov 24, 2002 3:51 pm
Hello, all php pro.
I did this
- Code: Select all
<html>
<head>
<title>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php $id=$_GET['id'];
switch ($id)
{case 'home': header("Location: home.php"); break;
case 'story': header("Location: story.php"); break;} ?>
</body>
</html>
and this came out when goto.php?id=story:
Warning: Cannot add header information - headers already sent by (output started at D:\Inetpub\wwwroot\php\gb\goto.php:9) in D:\Inetpub\wwwroot\php\gb\goto.php on line 12
why?
-
cooldownguy86
- New php-forum User

-
- Posts: 4
- Joined: Wed Nov 20, 2002 2:59 pm
-
by WillemM » Sun Nov 24, 2002 11:11 pm
You will need this instead of your code:
=== START OF DOCUMENT ===
<?php
$id = $_GET['id'];
switch ($id)
{
case 'home':
header("Location: home.php");
break;
case 'story':
header("Location: story.php");
break;
}
?>
=== END OF DOCUMENT ===
To make a long story short: Remove all html code before the php code.
Because headers must be sent first in PHP and then in the html code.
-
WillemM
- New php-forum User

-
- Posts: 3
- Joined: Sun Nov 24, 2002 10:28 am
by Oleg Butuzov » Mon Nov 25, 2002 2:32 am
do you remember what i told you last time ?
I told you - "read documentation"...
-
Oleg Butuzov
- Last Samuray

-
- Posts: 831
- Joined: Sun Jun 02, 2002 3:09 am
by mjr » Tue Nov 26, 2002 9:06 am
cooldownguy86 wrote:Hello, all php pro.
I did this
- Code: Select all
<html>
<head>
<title>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php $id=$_GET['id'];
switch ($id)
{case 'home': header("Location: home.php"); break;
case 'story': header("Location: story.php"); break;} ?>
</body>
</html>
and this came out when goto.php?id=story:
Warning: Cannot add header information - headers already sent by (output started at D:\Inetpub\wwwroot\php\gb\goto.php:9) in D:\Inetpub\wwwroot\php\gb\goto.php on line 12
why?
you cannot output headers (they are really HEADERS!!!!) after you output ANYTHING in output stream (like echoing, putting html code etc).
-
mjr
- New php-forum User

-
- Posts: 18
- Joined: Fri Sep 27, 2002 6:35 am
-
Return to PHP coding => General
Who is online
Users browsing this forum: No registered users and 3 guests