0

We are using today ASP classic and we moving to PHP. Someone know how can we do "Server.Transfer" in PHP?

ZippyV
  • 12,540
  • 3
  • 37
  • 52
Noamway
  • 155
  • 5
  • 21
  • 2
    possible duplicate of [Code Translation: ASP.NET Server.Transfer in PHP](http://stackoverflow.com/questions/471014/code-translation-asp-net-server-transfer-in-php) – Habib Jul 03 '12 at 09:09

3 Answers3

1

Its equivalent in php is require().

This is a link to its documentation :

http://php.net/manual/en/function.require.php

Vizard
  • 303
  • 1
  • 8
1

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();

TroySteven
  • 4,885
  • 4
  • 32
  • 50
0

If you want to change header of the page moving to another page, you can use header() function at php. Like this below.

<?php

    header("location:index.php?q='aAseWgjTJa132'");

?>
Htoo Maung Thait
  • 105
  • 2
  • 12
  • The OP asked about Server.Transfer. That's an ASP command that causes another page to execute and present as the originally requested page. Everything occurs on the server. Your answer does something different. It's akin to ASP's Response.Redirect command, which forces the client to make a new request. – trw Jan 13 '16 at 17:54