Forum Moderators: coopster
I have an index.html page with a link to a .php page
This is the complete code of the .php page
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<? header("Location: messages.php");?>
</body>
</html>
In other words when I click the hyperlink from index page this .php page should redirect me to another page right? after all that's only 1 command of PHP code
Instead I get the usual error
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/psa/home/vhosts/mysite.com/httpdocs/test.php:6)
Line 6 of test.php is "<? header("Location: messages.php");?>"
What is going on? The only thing I can think of is that my web provider is sending extra stuff or something that I'm not aware of altho it's not a free web hosting server.
Thanks for your help
You need to understand how the header function works. No output can be sent to the browser BEFORE you call this function. This includes any whitespace you have in your code. In your code you have this:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
BEFORE the header function.
Try reading up on it at PHP.net
http://uk2.php.net/manual/en/function.header.php [uk2.php.net]