Using PHP to load another page or html page | | |
Ive got a PHP script, which if it ends correctly, i want load another
PHP file or an HTML page automatically, ie without user intervention.
The new page shoud replace the current page on the browser. Is there a
PHP command or function which does this?
Thanks, | | | | re: Using PHP to load another page or html page
Fish44 schreef:[color=blue]
> Ive got a PHP script, which if it ends correctly, i want load another
> PHP file or an HTML page automatically, ie without user intervention.
> The new page shoud replace the current page on the browser. Is there a
> PHP command or function which does this?[/color]
Try something like this:
header('Location: page.php');
HTH.
Peter.
-- http://www.phpforums.nl | | | | re: Using PHP to load another page or html page
On Wed, 22 Mar 2006 10:10:24 -0800, Fish44 wrote:
[color=blue]
> Ive got a PHP script, which if it ends correctly, i want load another
> PHP file or an HTML page automatically, ie without user intervention.
> The new page shoud replace the current page on the browser. Is there a
> PHP command or function which does this?
>
> Thanks,[/color]
header ("location: <new url>"); | | | | re: Using PHP to load another page or html page
Fish44 wrote:[color=blue]
> Ive got a PHP script, which if it ends correctly, i want load another
> PHP file or an HTML page automatically, ie without user intervention.
> The new page shoud replace the current page on the browser. Is there a
> PHP command or function which does this?
>
> Thanks,
>[/color]
headers will work fine unless you've already sent data to the user, in
which case you'll need to use Javascript.
<script type="text/javascript">
location.replace("new_url");
</script>
That should work, but unless you can't, use the PHP header modification.
Burke | | | | re: Using PHP to load another page or html page
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. | | | | re: Using PHP to load another page or html page
Fish44 wrote:[color=blue]
> 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.
>[/color]
That's perfectly alright, we're all new at some point, I know I still am! ;)
You'll want to have the whole parenthesized part in quotes, like so:
header("Location: http://www.mitas.ie/");
....and that should do it.
The reason is that you're sending the browser the HTTP header "Location:
http://mitas.ie/", which tells it that the location it should be going
to is mitas.ie.
Good Luck!
Burke | | | | re: Using PHP to load another page or html page
Fish44 wrote:[color=blue]
> 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.
>[/color]
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 | | | | re: Using PHP to load another page or html page
No u havent confused me (too much). I'm already out of the 'header'
option, by the time i get to line 83, since the page is a login one,
and html has already been generated before the user presses the send
button which posts the data to the sever using php.
Ive used the javascript as follows
code-------------------------
if ($row["UserPass"]=="$Pass1")
{
echo( $tempName ."<br>" ."You are now logged in. <br>");
echo("<a href=\"some url\">go somewhere</a>");
echo("<script>
<!--
location.replace(\"some url\");
-->
</script>");
end code------------------.
So if the java fails, then the link is presented. Think this is a good
compromise
Many Thanks,
Fish44 | | | | re: Using PHP to load another page or html page
I add that no header information should be written before the
header('Location : page.php'); |  | | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 229,155 network members.
|