PHP page Jump Methods

Source: Internet
Author: User

PHP is the preferred language for web development by many programmers. In actual development, all the functions of the website can be met by compiling in PHP, such as PHP page Jump.

  • How to obtain the submitted data in the parsing sequence of PHP Variables
  • In-depth explanation of the PHP Operating Mechanism
  • Analysis of PHP function extract () Application Skills
  • Summarize some PHP information functions for you
  • PHP string query tips

    In a web system, redirecting from one web page to another is one of the most commonly used technologies in lamp projects. Page Jump may be caused by the user clicking a link or button, or automatically generated by the system. This section describes common methods for automatically page redirect in PHP.

    PHP page Jump 1. header () function

    The Header () function is a very simple method for page Jump in PHP. The main function of the header () function is to output the HTTP header to the browser.

    The Header () function is defined as follows:

    Void header (string [, bool Replace [, int http_response_code])

    The optional parameter replace indicates whether to replace the previous header or add a header of the same type. The default parameter is replace.

    The second optional parameter http_response_code sets the HTTP code as the specified value. The Location header in the header function is a special header call, which is often used to redirect pages. Note: 1. There cannot be spaces between location and:. Otherwise, no jump will be made.

    2. There cannot be any output before using the header.

    3. the PHP code after the header will also be executed. For example, redirect the browser to the official forum of the lamp brothers.

    [PHP]
    View plaincopyprint?
    1. <? PHP
    2. // Redirect the browser
    3. Header ("Location: http: // bbs. lampbrother.net ");
    4. // Ensure that subsequent code will not be executed after redirection
    5. Exit;
    6. ?>
    <? PHP // redirect the browser header ("Location: http: // bbs. lampbrother.net"); // After the redirection, the subsequent code will not be exit;?>

  • PHP page Jump 2. meta tag

    Meta tag is the tag that provides document meta information in HTML. You can use this tag in a PHP program to redirect pages. If http-equiv is defined as refresh, the page will be redirected to the corresponding page within a certain period of time based on the value specified by content.

    If you set content = "seconds; url = URL", it defines how long the page will jump to the specified URL. For example, the page automatically jumps to the lamp brothers' official forum after the meta tag is used to implement the vaccine.

    [HTML]
    View plaincopyprint?
    1. <Meta
      HTTP-equiv = "refresh"
    2. Content = "1; url = http: // bbs.lampbrother.net"
      >
    <   meta   http-equiv = "refresh"  content = "1;url=http:// bbs.lampbrother.net" >

    For example, the following meta. php program automatically jumps to bbs.lampbrother.net after one second of staying on the page.

    [HTML]
    View plaincopyprint?
    1. <? PHP
    2. $ Url = "http://bbs.lampbrother.net ";
      ?>
    3. <Html
      >
    4. <Head
      >
    5. <Meta
      HTTP-equiv = "refresh"
      Content = "1;
    6. Url = <? PHP echo $ URL;
      ?> ">
    7. </Head>
    8. <Body
      >
    9. The page stays for only one second ......
    10. </Body>
    11. </Html>
    <? PHP $ url = "http://bbs.lampbrother.net";?> <HTML> 

    PHP page Jump 3. Javascript

    For example, this code can be placed in any legal position in the program.

    [JavaScript]
    View plaincopyprint?
    1. <? PHP
    2. $ Url = "http://bbs.lampbrother.net ";
    3. Echo "<script language = 'javascript'
    4. Type = 'text/JavaScript '> ";
    5. Echo "window. Location. href = '$ url '";
    6. Echo "</SCRIPT> ";
    7. ?>
    <  ?php  $ url  =  "http://bbs.lampbrother.net" ;  echo " <   script   language = 'javascript'  type = 'text/javascript' > ";  echo " window.location.href = '$url' ";  echo " <  /script > ";  ?>

    The above are the three PHP page Jump implementation methods we will introduce to you.

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.