473,883 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 188003
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('Locatio n: 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.replac e("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\htdoc s\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\htdoc s\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("Locatio n: 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\htdoc s\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.replac e("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.replac e(\"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('Locatio n : page.php');

Mar 23 '06 #9

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

Similar topics

2
2320
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 middel (all actions run here), and on bottom html pages will be shown. The bottom page contains forms witch is developed with a 3ed party design tool from Acrobat and stored as HTML. It wouldn't be any problem storing these files as html. But the main...
2
3183
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 newbie at xml and xsl This is my xml("index.xml")page(I can not change this, it comes to me this way. <?xml version="1.0" encoding="iso-8859-1" ?>
1
2669
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 goes through all the HTML-pages on a site looking for words entered by the user. The results is thereafter presented to the user (it's a kind of a search-engine).
2
1944
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 like the secretary at a school to update a Word document concerning homework assignments. This Word document would reside on the server. When changes are made it, these changes are automatically updated to the web page. This would simplify life...
1
1954
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 values from a html form but if i want to populate some values in html form based on value retreived from database , how do i do it? Thanks in advance
9
2645
by: Skijor | last post by:
How do you go back to the html page you came in from from inside a php script?
1
4938
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" subject="Science"> <media id="2809"> <topic>A Bird's Paradise</topic> <category>Concept</category> <type>Animation</type>
4
4279
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 iFrame1 ) and it is supposed to load in an external .html page that has a flash video in it. The external .html page is supposed to load when a user clicks on a thumbnail image on the parent page. There are 20 external .html pages that a user can load in...
2
1341
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 want to use this value of year in my java script function function veiw() {
1
8210
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();"> <did = 'hi'>
0
9936
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10845
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9571
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7123
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5797
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5990
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4609
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4215
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.