美文网首页
2019-01-09【PHP跳转页面】

2019-01-09【PHP跳转页面】

作者: mahongyin | 来源:发表于2019-01-09 10:02 被阅读12次

    PHP跳转页面的几种实现方法详解

    •PHP页面跳转一、header()函数

    header()函数是PHP中进行页面跳转的一种十分简单的方法。header()函数的主要功能是将HTTP协议标头(header)输出到浏览器。

    header()函数的定义如下:

    void header (string string [,bool replace [,int http_response_code]])

    可选参数replace指明是替换前一条类似标头还是添加一条相同类型的标头,默认为替换。

    第二个可选参数http_response_code强制将HTTP相应代码设为指定值。 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转。

    注意:

    1.location和“:”号间不能有空格,否则不会跳转。

    2.在用header前不能有任何的输出。

    3.header后的PHP代码还会被执行。例如,将浏览器重定向到lamp兄弟连官方论坛

    代码如下:

    ```

    <  ?php 

    //重定向浏览器 

    header("Location: http://bbs. lampbrother.net"); 

    //确保重定向后,后续代码不会被执行 

    exit;

    ?>

    ```

    •PHP页面跳转二、Meta标签

    Meta标签是HTML中负责提供文档元信息的标签,在PHP程序中使用该标签,也可以实现页面跳转。 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。

    若设置content="秒数;url=网址",则定义了经过多长时间后页面跳转到指定的网址。例如,使用meta标签实现疫苗后页面自动跳转到LAMP兄弟连官方论坛。

    复制代码代码如下:

    <pre>

    <   meta   http-equiv = "refresh" 

    content = "1;url=http:// bbs.lampbrother.net" >

    </pre>

    例如,以下程序meta.php实现在该页面中停留一秒后页面自动跳转到bbs.lampbrother.net。 

    复制代码代码如下:

    <code>

    <  ?php 

    $ url  =  "http://bbs.lampbrother.net" ;  ?> 

    <   html > 

    <   head > 

    <   meta   http-equiv = "refresh"   content ="1; 

    url = <  ?php echo $url;  ?> " > 

    <  /head > 

    <   body > 

    页面只停留一秒…… 

    <  /body > 

    <  /html >

    </code>

    PHP页面跳转三、JavaScript

    例如,此代码可以放在程序中的任何合法位置。

    复制代码代码如下:

    ```

    <  ?php 

    $ url  =  "http://bbs.lampbrother.net" ; 

    echo " <   script   language = 'javascript' 

    type = 'text/javascript' > "; 

    echo " window.location.href = '$url' "; 

    echo " <  /script > "; 

    ?>

    ```

    以上就是我们向大家介绍的三种PHP页面跳转实现方法。

    ```

    <button type="button" class="btn btn-primary" onclick="window.location.href='reg.php'">注册</button>

    ```

    方法一:在button标签中加上onclick属性,赋值为Javascript

    <input type="button" name="register" value ="注册" onclick="window.location.href='Register.jsp'"/>

    <input type="button" value="我是一个按钮" onclick="javascrtpt:window.location.href='http://blog.sina.com.cn/mleavs'">

    方法二:触发一个函数跳转

    <script>

        function jump(){

            window.location.href="http://blog.sina.com.cn/mleavs";

        }

    </script>

    <input type="button" value="我是一个按钮" onclick=javascrtpt:jump()>

    方法三:a标签的超链接可以直接嵌套一个button

    <a href="https://www.baidu.com/">

        <button>点我跳转到度娘!</button>

    </a>

    方法四:表单的action定向提交跳转

    <form action="xx.html" method="post">

        <input type="bottom" value="按钮">

    </from>

    还有其他方法,有些方法一些浏览器可能会不支持。 

    ---------------------

    作者:田卡特

    来源:CSDN

    原文:https://blog.csdn.net/tjh625/article/details/81235827

    版权声明:本文为博主原创文章,转载请附上博文链接!

    相关文章

      网友评论

          本文标题:2019-01-09【PHP跳转页面】

          本文链接:https://www.haomeiwen.com/subject/rxrwrqtx.html