473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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,

Mar 22 '06 #1
8 187316
Fish44 schreef:
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?


Try something like this:

header('Location: page.php');

HTH.
Peter.
--
http://www.phpforums.nl
Mar 22 '06 #2
On Wed, 22 Mar 2006 10:10:24 -0800, Fish44 wrote:
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,


header ("location: <new url>");

Mar 22 '06 #3
Fish44 wrote:
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,

headers will work fine unless you've already sent data to the user, in
which case you'll need to use Javascript.

&lt;script type="text/javascript">
location.replace("new_url");
&lt;/script>

That should work, but unless you can't, use the PHP header modification.

Burke
Mar 22 '06 #4
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.

Mar 23 '06 #5
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.


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
Mar 23 '06 #6
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
Mar 23 '06 #7
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

Mar 23 '06 #8
I add that no header information should be written before the
header('Location : page.php');

Mar 23 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jon Haakon | last post by:
Hi, I'm developing a websolution using ASP and DHTML technology that's running on a MS IIS webserver. My solution is frame based with a toolbar on top, a hidden frame for scripts in the...
2
by: kmunderwood | last post by:
I am having trouble changing the font size when extracting xml into an html web page. I think it can be done so many ways, that my searches bring up examples that I am not familiar with. I am a...
1
by: Jeppe 1971 | last post by:
Hi Does anyone know of a way to load a HTML-page and examine the document without activating the code? I am trying to create a search-function in javascript. The idea is that the function...
2
by: KnotKnormal | last post by:
I would like to dynamically load a HTML page (or a Word document), which is embedded in a table when the user clicks on a hyperlink to go from HTML page one to HTML page two. For example, I would...
1
by: Priya | last post by:
Hi, I'm new to ASP.NET. I've some basic ques. In what situations we use aspx page when DHTML can be used? How can I interact between an aspx page & html page eg: using Request . Form i get the...
9
by: Skijor | last post by:
How do you go back to the html page you came in from from inside a php script?
1
by: basavaraj koti | last post by:
I need to show image using xslt Below provided in my xml and xslt. <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl" href="../xyz.xsl"?> <Grade class="03"...
4
by: djlender | last post by:
Hi All! I'm hoping someone can help me with this situation. I am a developer working on a project that has a video voting page. The situation is this: The parent page has an iFrame ( named...
2
by: abhishekbrave | last post by:
Hi I have a combo box having the values of year. <select name=year value=2008> <option value=2007>2007</option> <option value=2007>2006</option> <option value=2007>2005</option> </select>& I...
1
by: Duke | last post by:
<html> <head> <script type="text/javascript"> function init(){ var html = document.open('Hello.html'); document.getElementById('hi").innerHTML = html; } </script> <body onload ="init();">...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.