--- tarniadi <[EMAIL PROTECTED]> wrote:

> I want to know how to leave the current HTML page and load another 
> page with php code, if it is possible.
> 
> Adrian

First, keep in mind that the PHP script runs on the server and is completely
executed before it is sent to the web browser.  This client-server arrantement
takes some getting used to.

The real question is:  when do you want to load a new PHP or HTML page?

If you want the page to be loaded because of some user action after the page is
loaded, you have to use a Javascript (which runs in the browser) event to make
a change to the page url:

<script language="Javascript">
function goto_new_url()
{
 window.location="new_url"
}
</script>

and call goto_new_url() with some event handler in Javascript.


If the decision to go to a new page occurs during the processing of the PHP
script (ie before it is sent to the browser) then you have some additional
options.

PHP has a header() function where you can redirect the browser to look at a new
URL.

<?php
header("Location: new_url");
?>

However, this will only work properly if your opening <?php tag is at the very
top of the program.  This means it must be before any HTML tags and there can
be no spaces or blank lines above it.  Also, there must not be any print or
echo statements or other statements which generate output to the browser.  

If you do not do this, you will get an error message which says that the
headers cannot be modified because the headers have already been sent.  This is
one of the more confusing errors for beginners and a commonly asked question in
groups like this one.


You could use PHP to write a small section of Javascript code to redirect the
page as well.  This would work after some of the HTML is generated and sent to
the browser.  When the browser reaches the Javascript section, it would load
the new page.


There are other ways to accomplish this as well but these two or three
techniques will cover most situations.  Planning and good design is required.

James
_____



 

James D. Keeline
http://www.Keeline.com  http://www.Keeline.com/articles
http://Stratemeyer.org  http://www.Keeline.com/TSCollection

http://www.ITeachPHP.com -- Free Computer Classes: Linux, PHP, etc.
Fall Semester Begins Sep 7 -- New Classes Start Every Few Weeks.


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/HKFolB/TM
--------------------------------------------------------------------~-> 

Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to