Php header and redirect in asp _ PHP Tutorial

Source: Internet
Author: User
The php header is compared with the redirect in asp. Response is used to implement redirection in asp. redirect function: Usage example: response. redirect .. test. in aspphp, there are also similar functions: header Usage example: header (location :.. test. php), but the asp implements redirection using response. redirect function:
Example:
Response. redirect ".../test. asp"
Php also has similar functions: header
Example:
Header ("location: ../test. php ");
However, the two are different.
The redirect function of asp can work after the header file is sent to the customer.
For example

<% Response. redirect ".../test. asp" %>

The following code in php reports an error:

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

You can only do this:
Header ("location: ../test. php ");
?>
...
That is, the header function cannot send any data to the customer.

Let's look at the following example:
Asp

<%
Response. redirect ".../a. asp"
Response. redirect ".../B. asp"
%>

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

We found that it redirects B. php.
It turns out that after redirect is executed in asp, subsequent code will not be executed.
Php continues to execute the following code after executing the header.
In this regard, the header redirection in php is not as good as the redirection in asp. sometimes, after we want to redirect, we cannot execute the following code:
Generally, we use
If (...)
Header ("...");
Else
{
...
}
However, we can simply use the following method:
If (...)
{Header ("..."); break ;}

Response Function: Usage example: response. redirect .. /test. asp php also has a similar function: header Usage example: header (location :.. /test. php); but the two...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.