PHP页面跳转几种实现方法

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

 header函数中Location类型的标头是一种特殊的header调用,常用来实现页面跳转

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

2、"Localtion:"后面有一个空格。

3、在用header前不能有任何的输出,所以此函数只能放在文件的顶端。

示例:此例会自动跳转到百度首页

< ?php
header("Location: http://www.baidu.com");
exit;
?>

 

PHP页面跳转二、Meta标签

 若定义http-equiv为refresh,则打开该页面时将根据content规定的值在一定时间内跳转到相应页面。若设置content="秒数;url=网址",则定义了经过多长时间后页面跳转到指定的网址。

示例:此例会自动跳转到冠威博客首页

< ?php
$url = "http://www.guanwei.org"; ?>

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

 

PHP页面跳转三、JavaScript(常用、推荐)

示例1:此例会自动跳转到冠威博客首页

< ?php
$url = "http://www.guanwei.org";
echo "";
?>

示例2:此例会自动跳转到冠威博客首页

发布了1176 篇原创文章 · 获赞 311 · 访问量 485万+
展开阅读全文

Php单选按钮选择

12-13

<div class="post-text" itemprop="text"> <p>I am having trouble with getting the radio buttons to work with my select statement the issue lies somewhere in the buttons i think but i am unsure of this any and all help is appreciated </p> <p>here is the code that i have currently. what i need to happen is for the page to refresh and sort the table to what has been selected by the button</p> <pre><code> <?php require_once('dbadmin.php');?> <?php session_start(); $user = $_SESSION['user']; if(!isset($user)){ header("Location:admin_login.php"); } ?> <h1>Reports</h1> <table border="1" style="width:100%"> <tr> <th>First Name</th> <th>Last Name</th> <th>Email</th> <th>Distance</th> </tr> <?php include('dbadmin.php'); $select = "SELECT `fname`, `lname`, `email`, `distance` FROM runner ORDER BY `lname`"; $result = mysql_query($select) or die ('Oops! '.mysql_error($connect)); if(isset($_POST['submit_sort'])){ $radio = $_POST['radiosort']; if($radio =='fname'){ $select = "SELECT `fname`, `lname`, `email`, `distance` FROM runner ORDER BY `fname`";} else if($radio =='lname'){ $select = "SELECT `fname`, `lname`, `email`, `distance` FROM runner ORDER BY `lname`";} else if($radio =='distance'){ $select = "SELECT `fname`, `lname`, `email`, `distance` FROM runner ORDER BY `distance`";} $result = mysql_query($select) or die("Invalid query: ".mysql_error($connect)); } if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_assoc($result)) { echo '<tr><td>'.$row['fname'].'</td>'; echo '<td>'.$row['lname'].'</td>'; echo '<td>'.$row['email'].'</td>'; echo '<td>'.$row['distance'].'</td></tr>'; } } ?> <form name="reports" id="reports" action="reports.php"> <label for="submit_sort" style="font-weight:bold;">Sort By:</label><br> <input name="radiosort" type="radio" title="sort" id="lname" value="lname"> <label for="lname">Last Name</label><br> <input name="radiosort" type="radio" title="sort" id="fname" value="fname"> <label for="fname">First Name</label><br> <input name="radiosort" type="radio" title="sort" id="distance" value="distance"> <label for="distance">Distance</label><br><br> <input type="submit" name="submit_sort" title="submit_sort" id="submit" value="Submit"> </form> </table> </code></pre> </div> 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 1024 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览