PHP redirect to another page via a blank page

Sounds simple, but I'm already confused. How do I redirect to another page and in between I want to show a blank page with some texts for a certain time. I was looking for sleep (); and other options, but none of them offer what I want.

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

}

?>

      

+3


source to share


4 answers


In addition to our discussion of comments, my suggestion is as follows:

page1.php:

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

      

page2.php



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

      

Page3.php

<?php
// This would be your Item List, or whatever you were redirecting to
?>

      

+1


source


Redirect the guy to this page after successful sign up or registration.

main_refresh_landing.php

header("Refresh: 5; url=someurl.php");
echo "Congrats, there some text waiting for you---->";
//user will be redirected after 4 seconds.

      



Or better

    <?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


source


Redirect paths

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>.';
?>

      

Meta tag :

echo '<meta http-equiv="refresh" content="5; URL=http://localhost/view.php">';

      

JavaScript

If it should be in a script, use setTimeout like:

echo "<script>setTimeout(function(){
   window.location.open('http://localhost/view.php');
}, 5000);</script>";

      

0


source


You have to use javascript for this.

Php code must be executed and then displayed in browser

so sleep while executing your script ...

in javascript you can do this

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

      

The page loads with whatever you want to display, waits 3000ms (i.e. 3 seconds) and redirects to google.com.

Greetings

0


source







All Articles