Home > Backend Development > PHP Tutorial > Comparison of php header and redirect in asp_PHP tutorial

Comparison of php header and redirect in asp_PHP tutorial

WBOY
Release: 2016-07-21 16:06:22
Original
968 people have browsed it

To implement redirection in asp, the response.redirect function is used:
An example of usage:
response.redirect "../test.asp"
There is a similar function in php: header
An example of usage:
header("location:../test.php");
But there is a difference between the two.
ASP’s redirect function can work after sending the header file to the customer.
Such as


<%response.redirect "../test.asp"%>
Check if the following example code in php will report an error:

header("location:.. /test.php");
?>

You can only do this:
header("location:../ test.php");
?>
...
i.e. header No data can be sent to the client before the function.

Look at the following example:
asp in

< %
response.redirect "../a.asp"
response.redirect "../b.asp"
%>

The result is to redirect the a.asp file. What about
php?
header("location:../a.php");
header("location:../ b.php");
?>

We found it redirected b.php.
It turns out that after executing redirect in asp, the following code will not be executed.
After executing the header, php will continue to execute the following code.
In this regard, the header in php is important. Orientation is not as good as redirection in asp. Sometimes we cannot execute the following code after redirection:
Generally we use
if(...)
header("...");
else
{
...
}
But we can simply use the following method:
if(...)
{ header("..." );break;}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315442.htmlTechArticleThe response.redirect function is used to implement redirection in asp: Usage example: response.redirect ../test.asp There are similar functions in php: header usage example: header(location:../test.php); But both...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template