PHP通过空白页面重定向到另一个页面

时间:2015-07-31 12:03:45

标签: php redirect url-redirection

这听起来很容易,但我已经纠缠不清了。如何重定向到另一个页面,在中间我希望显示一个空页面,其中包含特定时间的某些文本。我寻找睡眠();和其他选择,但没有一个提供我想要的。

<?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" );

}

?>

4 个答案:

答案 0 :(得分:1)

成功进入或注册后,将此人重定向到此页面。

<强> 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...";
    }

    }

答案 1 :(得分:1)

继我们对意见的讨论之后,我的建议如下:

<强> page1.php中:

var data = File
    .ReadAllLines(textfiletest)
    .Select(x => x.Split(':'))
    .Where(x => x.Length > 1)
    .ToLookup(x => x[0].Trim(), x => x[1]);

<强>使page2.php

<?php
// your sql query as before
if($run2)
    header("Location: Page2.php"); // normal redirect after completing your sql query
?>

<强> Page3.php

<?php
header("refresh:5;url=Page3.php" );
echo "Confirmation message displayed for 5 seconds before redirect";
?>

答案 2 :(得分:0)

重定向方式

<强> 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>";

答案 3 :(得分:0)

你应该使用javascript。

应该执行Php代码然后在浏览器中显示

执行脚本时睡不着......

在javascript中你可以这样做

<script>setTimeout(function() {window.location="http://www.google.com";}, 3000);</script>

页面加载您想要显示的内容,等待3000毫秒(即3秒)并重定向到google.com。

干杯