Entry
How do you redirect from one PHP file to another without notifying the user's browser to redirect?
Using the same MVC model as J2ee how do you pass information to the forwarded php w/o storing the da
Mar 15th, 2008 22:20
dman, ha mo, Articles Hosting, Scott Kingdon, William Steve Applegate, alex torres, http://www.ttnr.org
I would like to control several pages with one PHP page. Based on
user
needs I would like to forward the request to another file. If I use
include I guess it would work about the same. Will the included script
get parsed? It is more of a control and management thing than
anything
else. This is what I am used to when working with Java Servlets, JSPs
and JavaBeans. By doing this you can separate the input from the
output. All updates to the database are done with the controler script
and all the display is done with the other. It also makes for easy
upgrading and modification.
The reason you do NOT want to do it through the user agent is the
browser registers two pages. If you are redirecting to an external
page
that is OK. If you are redirecting to an internal page this is a
problem. When the user wants to browse back they get redirected. They
must go back two pages. This is an eyesore and sloppy. I would never
recommend using this style of redirect. Many internet users still do
not know how to go back multiple pages (sad but true).
For these reasons Java has implemented request forwarding in addition
to include. The biggest difference being organization and forwarding
flushes all buffered output. It is a very usefull feature. It appears
the only thing we have in PHP is to include the file. It is not a bad
alternitive but it is not what I was hoping for. If that is all I have
then I will use that.
///////////////////////
old response
///////////////////////
Well... To the best of my knowledge, HTTP redirections are done
through the user agent. include()-ing the file you want to process the
request is the only way I know to avoid the browser redirecting. Could
you explain exactly why you need a *real* redirection?
///////////////////////
old response
///////////////////////
What?
I want to redirect, not include. Using an MVC model, I want to use one
PHP file to redirect requests. Here are two ways that are
insufficient:
-----------------------
<?
$URL="somedomain.com";
header ("Location: $URL");
?>
<html>
<title></title>
<head></head>
<body>
</body>
</html>
-----------------------
<html>
<head>
<meta http-equiv="refresh" content="5; url=http://www.somewhere.com">
</head>
<body>
</body>
</html>
-----------------------
The reason why these are not acceptable is they send the redirect to
the browser. Then the browser redirects. Now when the user clicks
back....things are screwed! The user has to click back twice.
What I want is to for my PHP script to redirect directly to another
script. This is called request forwarding. A GET/POST request is
received. The request can not be handled here so it is forwarded to
another script which then returns to the browser. Notice there is no
redirect sent to the browser.
The only way I have bee able to simulate this is to open the script I
want to redirect to and then send the contents back to the user. This
gives the illusion of redirecting the request. This is not a very good
way to do it but it is far better than sending the redirect back to
the
browser.
Any suggestions?
=======================
///////////////////////
old response
///////////////////////
Easy ! Use the include() directive :
if ($flag == "raised")
include("otherfile.php");
else {
// Proceed as usual
}
=======
webmasterworld.com/forum92/4315.htm
i hope that helps.