Code Translation: ASP.NET Server.Transfer in PHP

How do I do this in PHP?

Server.Transfer("/index.aspx") 

(add ';' for C #)

EDIT:

It is important that the URL remains the same as before; you know for google. In my situation, we have a bunch of .html files that we want to transfer, and it is important for the client that the address bar does not change.

+3
source share
3 answers

As far as I know, PHP does not have the real ability to pass, but you can get exactly the same effect using include () or require (), like so:

 require_once('/index.aspx"); 
+5
source

The easiest way is to use header redirection.

 header('Location: /index.php'); 

Edit: Or you can just include the file and exit if you don't want to use HTTP headers.

+2
source

Using require will be similar to server.transfer, but in some cases the behavior will be slightly different. For example, when the output has already been sent to the browser and use is required, the output already sent to the browser will be shown, as well as the path that you need.

The best way to simulate C # / ASP.NET Server.Transfer () is to properly set up PHP output buffering, and then use the following function that I wrote.

 function serverTransfer($path) { if (ob_get_length() > 0) { ob_end_clean(); } require_once($path); exit; } 

Setting up output buffering is as simple as using ob_start () as the first line your PHP application calls. More information can be found here: http://php.net/manual/en/function.ob-start.php

ASP.NET provides default output buffering, so this is not necessary when using Server.Transfer ();

0
source

All Articles