Page 1 of 1

how to redirect to a page without a trip to the client

Posted: Tue Oct 19, 2004 5:21 am
by jasongr
Hello

While processing page A in my server, I realize that I need to redirect the user to page B (both under the same domain own by me).
If I trigger the following code:

Code: Select all

header("Location: http:// <my domain> /B.php");
exit;
while this indeed works, it triggers a second trip to the server. In fact page A returns to the client where the redirect is triggered and then I return to the server to serve page B.

I was wondering if there is a possiblity to redirect to a page without performing the extra trip to the server. Here is my rationale: since I am already in the server when I am processing page A and page B is a page under the same domain as page A, then I don't see a reason why I should be able to do it.

I would appreciate any thoughts and help on this issue

Posted: Tue Oct 19, 2004 5:37 am
by timvw
if you want to redirect them, you will have another page request.

you could also [php_man]include[/php_man]/[php_man]require[/php_man] the page to avoid that.

Posted: Tue Oct 19, 2004 5:43 am
by Weirdan
timvw wrote:if you want to redirect them, you will have another page request.

you could also [php_man]include[/php_man]/[php_man]require[/php_man] the page to avoid that.
or perform Apache virtual subrequest.
Reference:
  • [php_man]virtual[/php_man]

Posted: Tue Oct 19, 2004 5:51 am
by jasongr
I cannot rely on apache because my "redirects" are application specific and should be triggered on very specific scenarios

How can include or require help me here?
I need to reset the $_GET and _POST arrays, also the $_SERVER array and basically any other global information that is automatically generated by PHP for me.
I need to simulate a real redirect without causing a page request from the client

Also, I have already used require_once and include_once in my code and I need to "reset" PHP memory so it will allow me to require or include them again (once again I need to have a real "redirect on the server side")

I cannot change a require_once to a require because my code depends on the fact that classes cannot be inluded more than once

Posted: Tue Oct 19, 2004 6:08 am
by Weirdan
jasongr wrote:I cannot rely on apache because my "redirects" are application specific and should be triggered on very specific scenarios
Have you followed the link I gave to you? [php_man]virtual[/php_man] is called from within PHP.

Posted: Tue Oct 19, 2004 11:49 am
by timvw
jasongr wrote: I need to reset the $_GET and _POST arrays, also the $_SERVER array and basically any other global information that is automatically generated by PHP for me.
I need to simulate a real redirect without causing a page request from the client
Use [php_man]curl[/php_man] to request the page with the proper POST/GET vars and then otuput the result of that page. This way, the extra hit is generated by PHP and not the client.