|
Posted by burke on 03/23/06 03:36
Fish44 wrote:
> Tried the Header option first but could not get it to work,
>
> code ---------------
> 83 echo( $tempName ."<br>" ."You are now logged in. <br>");
> 84 header(Location:"http://www.mitas.ie/");
> 85 exit;
> code end---------
>
> My browser tells me that i have an error on that line.
> Parse error: syntax error, unexpected ':' in c:\Apache\htdocs\login.php
> on line 84
>
> Apologies guys but im pretty new at php.
>
Sorry, I should have noticed this before.
You can't send any output to the client (#83), and *then* send extra
headers (#84).
The reason is this: When you send your first output (probably your first
html block or echo statement), your server sends HTTP headers, which
tell the browser about the page it's downloading. HTTP headers are only
downloaded once, just before the real transmission starts.
So when you use header(), you're actually sending your own custom HTTP
headers, but this has to be the first thing you send, otherwise PHP will
yell at you, because when you called echo(), it started transmitting
data, which makes any proceeding calls to header() non-functional.
So what do you do?
three options:
1) scrap any output (ie. line #83) and just send the header.
2) use a meta-refresh -- you'll have to ask someone else about this,
I've never done it.
3) use Javascript instead
You can do a javascript redirect after the browser has already loaded
content. Just insert this code:
<script>
<!--
location.replace("http://mitas.ie");
-->
</script>
This will make the browser instantaneously go to the URL.
Here's the downside to Javascript: If someone has Javascript disabled in
their browser, they do nothing, They just sit there, waiting for the
page to change. The solution is to provide a link as well.
I would recommend just dropping all the echoes and html, and just
sending the header.
Hope I haven't just confused you -- I'm pretty sure I've written this
with enough convolution to confuse myself.
Burke
Navigation:
[Reply to this message]
|