Jump to content

Display "loading Page" While Php Script Is Getting Data


Johnny2

Recommended Posts

Right when my user logs in, the login.php file sends them to another file (we'll call it File_2) which takes about 21 seconds to load... so the user is staring at the filled-in login form for 21 seconds before they see anything else happen.

 

After the user clicks the login button, I'd like to display something to the user which indicates the page is loading.

 

At the end of "File_2", after it is all finished gathering data, it displays the html.

 

I'm having difficulty figuring out how to display a "loading" message while the user waits. Any help would be appreciated.

 

I've tried having the user sent from the login.php file to "File_1" THEN to "File_2", but this didn't work. It had the same effect as if the user was sent from login.php directly to "File_2".

 

Code I've used:

 

In login.php file:

// After the user is granted permission to login:
header("Location: File_1.php");
exit;

 

File_1 (where I was trying to show the user "Page is Loading", while they waited:

<?php
session_start();
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Loading</title>
</head>
<body>
<h1>The Page is Loading.  This may take a few moments.</h1>
</body>
</html>

<?php
header("Location: File_2.php");
exit;
?>

 

Then File_2 is just the page that loads, but the user doesn't see anything happen for 21 seconds.

Edited by Johnny2
Link to comment
Share on other sites

Are you doing this with AJAX or something? Why the long load time? If you're using header() to redirect, that redirect should be instantaneous (thought the page the user gets redirected to may show a blank white page as it loads).

 

...I think the bigger question here is why your page is taking 20+ seconds to load though. Loading page or not, you actually expect people to wait around for that? I wouldn't.

Link to comment
Share on other sites

Are you doing this with AJAX or something? Why the long load time? If you're using header() to redirect, that redirect should be instantaneous (thought the page the user gets redirected to may show a blank white page as it loads).

 

...I think the bigger question here is why your page is taking 20+ seconds to load though. Loading page or not, you actually expect people to wait around for that? I wouldn't.

It's not always 21 seconds. It can be as low as 2 seconds if a bunch of info doesn't have to be gotten from databases for the particular user. But for the users that need more information gathered, I wanted a loading message to display.

Link to comment
Share on other sites

I imagine you'd need to do this with AJAX -- redirect to a loading page on login, load the data using AJAX (saving the data into a session variable? It depends how much data you need to save?), and only redirect using Javascript once the AJAX request returns the data. You can use header() to redirect to the loading page, but you'd need to redirect using a Javascript method for the second redirect, since header() won't work if something has already been shown in the browser already.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...