How to implement page jump using header () in php _ PHP Tutorial

Source: Internet
Author: User
In php, the header () implements the page jump method. In this article, we use the header () function to perform page Jumps. we will introduce status redirects such as 404,302,301. below are a lot of status-based custom functions that can be tested. Heade this article uses the header () function to implement page Jumps. we will introduce status jumps such as 404,302,301. below are many status-based custom functions that can be tested by anyone who needs them.

302 temporary redirection for headers

The code is as follows:
Header ("HTTP/1.1 302 Found ");
Header ("Location: http://www.hzhuti.com ");

The page cannot be found because the header is 404

The code is as follows:
Header ("HTTP/1.1 404 Not Found ");

The following functions can be used to redirect to different states:

The code is as follows:

/**
* Jump to the page
*
* Use header () to jump to the page without displaying any content. if you cannot use header to jump to the page
* @ Param string $ url
* @ Param int $ status
*/
Function goto ($ url, $ status = null)
{
If (! Empty ($ status ))
{
$ Status = intval ($ status );
$ Codes = array (
100 => "Continue ",
101 => "Switching Protocols ",
200 => "OK ",
201 => "Created ",
202 => "Accepted ",
203 => "Non-Authoritative Information ",
204 => "No Content ",
205 => "Reset Content ",
206 => "Partial Content ",
300 => "Multiple Choices ",
301 => "Moved Permanently ",
302 => "Found ",
303 => "See Other ",
304 => "Not Modified ",
305 => "Use Proxy ",
307 => "Temporary Redirect ",
400 => "Bad Request ",
401 => "Unauthorized ",
402 => "Payment Required ",
403 => "Forbidden ",
404 => "Not Found ",
405 => "Method Not Allowed ",
406 => "Not Acceptable ",
407 => "Proxy Authentication Required ",
408 => "Request Time-out ",
409 => "Conflict ",
410 => "Gone ",
411 => "Length Required ",
412 => "Precondition Failed ",
413 => "Request Entity Too Large ",
414 => "Request-URI Too Large ",
415 => "Unsupported Media Type ",
416 => "Requested range not satisfiable ",
417 => "Expectation Failed ",
500 => "Internal Server Error ",
501 => "Not Implemented ",
502 => "Bad Gateway ",
503 => "Service Unavailable ",
504 => "Gateway Time-out"
);
If (array_key_exists ($ status, $ codes )){
$ Code = $ status;
$ Msg = $ codes [$ status];
$ Status = "HTTP/1.1 {$ code} {$ msg }";
} Else {
$ Status = null;
}
}
If (! Empty ($ status )){
Header ($ status );
}
If (! Empty ($ url )){
$ Url = url ($ url); header ("Location: $ url ");
If ($ code = 404 ){
Echo" ";
}
}
Exit;
}

The Progress () function is used to perform page Jumps. we will introduce status jumps such as 404,302,301. There are many status-based custom functions that can be tested. Heade...

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.