How would I do this in PHP?
Server.Transfer("/index.aspx")
(add ‘;’ for C#)
EDIT:
It is important to have the URL remain 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 to the client that the address bar doesn’t change.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
As far as I know PHP doesn’t have a real transfer ability, but you could get the exact same effect by using include() or require() like so:
require_once('/index.aspx");
Method 2
The easiest way is to use a header redirect.
header('Location: /index.php');
Edit:
Or you could just include the file and exit if you don’t want to use HTTP headers.
Method 3
Using require will be similar to server.transfer but it’s behavior will be slightly different in some cases. For instance when output has already been sent to the browser and require is used, the output already sent to the browser will be shown as well as the path you are requiring.
The best way to mimic C#/ASP.NET Server.Transfer() is to properly setup PHP Output Buffering and then use the following function 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 called by your PHP application. More information can be found here: http://php.net/manual/en/function.ob-start.php
ASP.NET enables output buffering by default, which is why this isn’t necessarily when using Server.Transfer();
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0