Forum Moderators: coopster

Message Too Old, No Replies

Page redirection worst case senario :(

         

Pointman

6:33 pm on Jan 23, 2005 (gmt 0)

10+ Year Member



Ok I'm a newbie to php but I can't figure this out

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

dreamcatcher

6:50 pm on Jan 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Pointman,

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]

Pointman

7:32 pm on Jan 23, 2005 (gmt 0)

10+ Year Member



Thanks. It's kind of missleading that when you create a new .php page in a program like dreamweaver it gives you a file with the typical <HEAD><BODY> skeleton. Didn't know you could simply start your file with <?php

Thanks again :)

dreamcatcher

8:24 pm on Jan 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



LOL! Glad you got it sorted. :)