美文网首页
PHP实现页面跳转方法

PHP实现页面跳转方法

作者: 一寸红蓝 | 来源:发表于2018-01-02 22:44 被阅读0次

  本文介绍PHP实现页面跳转的三种方法,分别是PHP提供的header()函数、html的meta标签和JavaScript脚本,下面分别介绍这三种方法的具体实现方式。

PHP的head()函数

<?php 
    header("Location: http://www.baidu.com"); 
    //后续代码不会被执行 
    exit;
?>

JavaScript脚本

<?php  
    $url = "http://www.baidu.com" ; 
    echo"<script language = 'javascript'  type = 'text/javascript'>";  
    echo" window.location.href = '$url'";  
    echo" </script>";  
?>

html的meta标签

<?php   
    $url = "http://www.baidu.com"; 
?>  
<html>    
    <head>    
        <meta http-equiv = "refresh"  content ="0.00.1; 
        url = <?php echo $url;?>">    
    </head>    
    <body>    
        页面只停留一秒……   
    </body >  
</html >

测试html代码

<!DOCTYPE html>
<html>
<body>
    <form action="http://127.0.0.1/1.php">
        用户名:<br>
        <input type="text" name="Username" value="admin">
        <br> 密码:<br>
        <input type="text" name="Password" value="123456">
        <br><br>
        <input type="submit" value="确定">
    </form>
    <p>点击确定,表单数据将发送到text.php页面,然后该页面自动跳转至百度首页</p>
</body>
</html> 

相关文章

网友评论

      本文标题:PHP实现页面跳转方法

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