Jump to content

PHP Loading


Norin

Recommended Posts

Hello, I'd like to add a Loading screen to my web site but the problem is that this loading screen must appear BEFORE the page actually load.

 

When I open my site, it says "Waiting for localhost..." then everything appears really fast, so all the loading scripts I found are not working since they get activated while the page is loaded, which is really fast.

 

I'd like the loading to show when it says "Waiting for localhost..." I tried to make a php file to redirect to my page but showing "Loading..." but I did not got it working.

 

Thanks

Link to comment
Share on other sites

You could use a meta redirect and set the redirect time to be like 10 seconds, that way the page is always displayed for 10 seconds before being redirected?

 

Maybe I am unclear on what you are really asking for/wanting??? You might also try the sleep() function www.php.net/sleep

Link to comment
Share on other sites

your really looking for an Ajax solution here. PHP allone has no way of knowing when your page has loaded, this all happens client side.

 

Honestly, if your page is taking that long to load that it needs a 'loading...' page, something is seriously wrong.

Link to comment
Share on other sites

You could use buffering

 

www.php.net/ob_start

www.php.net/ob_end_clean

www.php.net/ob_get_contents

 

example:

 

<?php
echo 'Page is loading please wait...<br />';
ob_start();
echo 'This is echoed in the buffer portion. <br />';
for ($i=0;$i<50000; $i++) {
    echo $i . ' time<br />';
}
echo 'This is the end of the buffer section';
$output = ob_get_contents();
ob_end_clean();

echo 'The output is read <br />';
echo $output;
?>

 

Now this in coordination with div tags and javascript you can have it dynamically remove the page loading etc.

 

Hope this helps.

Link to comment
Share on other sites

www.php.net

 

My best learning source. Never read any books, I found them very disappointingly stupid.

 

I started with Javascript than moved to php. Perhaps the biggest push was a friend asked me to create a movie webfetch. From there he asked me to modify some blog code and yea. Programming came pretty easy.

 

I am 22, been programming since I was 13.

Link to comment
Share on other sites

You could use buffering

 

www.php.net/ob_start

www.php.net/ob_end_clean

www.php.net/ob_get_contents

 

example:

 

<?php
echo 'Page is loading please wait...<br />';
ob_start();
echo 'This is echoed in the buffer portion. <br />';
for ($i=0;$i<50000; $i++) {
     echo $i . ' time<br />';
}
echo 'This is the end of the buffer section';
$output = ob_get_contents();
ob_end_clean();

echo 'The output is read <br />';
echo $output;
?>

 

Now this in coordination with div tags and javascript you can have it dynamically remove the page loading etc.

 

Hope this helps.

 

Your code does what I would like to do but instead of having a numbers of times a number is shown, I'd like it to include a page. I tried to replace the "for" with my "include" but it does not work... It just waits untill it has loaded everything THEN it shows everything in one block.

Link to comment
Share on other sites

<?php
echo 'Page is loading please wait...<br />';
ob_start();
echo 'This is echoed in the buffer portion. <br />';
include('yourfile.php');
echo 'This is the end of the buffer section';
$output = ob_get_contents();
ob_end_clean();

echo 'The output is read <br />';
echo $output;
?>

 

Try that maybe?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.