[英]PHP redirect to another page through a blank page
这听起来很容易,但我已经让自己纠结了。 我如何重定向到另一个页面,在此期间我希望在特定时间显示一个带有一些文本的空页面。 我找了 sleep(); 和其他选项,但没有一个提供我想要的。
<?php
require ('config.php');
if(isset($_POST['check']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$gender = $_POST['gender'];
$date = $_POST['date'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$cnic = $_POST['cnic'];
$mail = $_POST['mail'];
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$cell = $_POST['cell'];
$complete_add = $add1 . " ". $add2;
$query = "INSERT INTO login(username, password) VALUES('$uname', '$pass')";
$run = mysql_query($query);
if(!$run)
{
echo "Failed: Username already registered <br>";
die();
}
$query2 = "INSERT INTO signup(First_Name, Last_Name, Gender, Birth_Date, Address, NIC, Email, Username, Password, Contact)
VALUES('$fname', '$lname', '$gender', '$date', '$complete_add', '$cnic', '$mail', '$uname', '$pass', '$cell')";
$run2 = mysql_query($query2);
echo "Congratulations! You have registered now. <br> You will now be redirected to Item lists...";
// sleep(5);
exit(header('Location: view.php'));
// header( "refresh:2;url=http://localhost/view.php" );
}
?>
继我们对评论的讨论之后,我的建议如下:
第1页.php:
<?php
// your sql query as before
if($run2)
header("Location: Page2.php"); // normal redirect after completing your sql query
?>
页面2.php
<?php
header("refresh:5;url=Page3.php" );
echo "Confirmation message displayed for 5 seconds before redirect";
?>
第3页.php
<?php
// This would be your Item List, or whatever you were redirecting to
?>
成功进入或注册后,将该人重定向到此页面。
main_refresh_landing.php
header("Refresh: 5; url=someurl.php");
echo "Congrats, there's some text waiting for you---->";
//user will be redirected after 4 seconds.
或更好
<?php
require ('config.php');
if(isset($_POST['check']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$gender = $_POST['gender'];
$date = $_POST['date'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$cnic = $_POST['cnic'];
$mail = $_POST['mail'];
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$cell = $_POST['cell'];
$complete_add = $add1 . " ". $add2;
$query = "INSERT INTO login(username, password) VALUES('$uname', '$pass')";
$run = mysql_query($query);
if(!$run)
{
echo "Failed: Username already registered <br>";
die();
}
$query2 = "INSERT INTO signup(First_Name, Last_Name, Gender, Birth_Date, Address, NIC, Email, Username, Password, Contact)
VALUES('$fname', '$lname', '$gender', '$date', '$complete_add', '$cnic', '$mail', '$uname', '$pass', '$cell')";
$run2 = mysql_query($query2);
if($run2)
{
header("Refresh: 2; url=main_refresh_landing.php");
echo "Congratulations! You have registered now. <br> You will now be redirected to Item lists...";
}
}
重定向方式
PHP
<?php
header( "refresh:5;url=view.php" );
echo 'You\'ll be redirected in about 5 secs. If not, click <a href="view.php">here</a>.';
?>
元标记:
echo '<meta http-equiv="refresh" content="5; URL=http://localhost/view.php">';
JavaScript :
如果必须在脚本中使用 setTimeout ,例如:
echo "<script>setTimeout(function(){
window.location.open('http://localhost/view.php');
}, 5000);</script>";
您应该为此使用 javascript。
Php 代码应该执行然后显示在浏览器中
所以在执行脚本时睡觉......
在javascript中你可以做到这一点
<script>setTimeout(function() {window.location="http://www.google.com";}, 3000);</script>
该页面加载了您想要显示的任何内容,等待 3000 毫秒(即 3 秒)并重定向到 google.com。
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.