tags:

views:

236

answers:

4

Can I Stop or interrupt PHP script for particular time?

I would like to implement logic like below:

on mydomain.com/index.php there will be flash appear showing some intro of a product for suppose 20 sec. Once it complete, on same index.php page the home page of site will appear.

I am not aware about flash (action script).

Is it possible in PHP or Javascript ?

+2  A: 

There isn't a need to interrupt PHP in the scenario given. Though I think what you want is to load the rest of the HTML after a certain event occurs.

If thats the case then you can use AJAX to load the additional HTML from the server. Or you can use CSS to hide that content and show it after a certain point.

Darrell Brogdon
+4  A: 

Usually "splash pages", as the're called, are made up of a seperate page.

In flash you can use the following code (Actionscript 3). Put it int the last frame, or use an event listener to redirecrect when the file is finished. The actual redirect looks like this:

getURL("http://www.woursecondpagehere.com", "_self")

Where you place it is up to you.

EDIT: I think that this is a reliable solution because this guarantees (if implemented correctly) that the page won't move until Flash is done. CSS and Javascript will work fine too.

Moshe
+1  A: 

The META Refresh tag is probably not what you want since it will redirect the user after 20 seconds, regardless of how long it took to load your Flash file, then play it. Since the speed of the user's connection cannot be reliably predicted, you will probably end up with a poor user experience.

What you want to do is definitely possible but it will involve some interaction between the Flash object and the rest of your page. If you could do as Moshe suggested and simply have the Flash object redirect the user's browser to your actual home page with content on it, that would be easier.

If you insist on keeping everything on the same page, one way to do it is to call a Javascript function from the Flash object once it's finished playing. The function you call should be written to hide the Flash object and/or it's container and display the container () with all of your content that you're ready to show.

See this Codefidelity blog post for a quick tutorial on how to call JS functions from Flash.

Also, to clarify, you won't be interrupting or changing when your PHP script runs. That runs on the server before the page is created and sent back to the user's browser. All you need to do is structure the HTML/CSS of your page to have two DIVs: one with the Flash object in it and the other with all your normal page content. However, set the CSS to only show the DIV with the Flash object, then finally use Javascript to hide that DIV and show the one with the content in it.

Armen
A: 

Try this, write the your flash (splash screen) <embede> code in index.html and simply use javascript redirect function with javascript timer functions to redirect to index.php where you actual content is there.

something like...

window.location = "http://your.domain.name/index.php"

or

location.href = "http://your.domain.name/index.php"

use setTimeout() to call redirect after specified time.

Pragati Sureka
You cannot predict how long it will take for the flash to end. So `setTimeout`, just like `redirect` is a bad solution.
xtofl
if its my flash i will know exactly how long its gonna play and i can set time according to that..... the solution i posted is for people who dont know flast/actionscript much.. this is a simple way of doing what he asked
Pragati Sureka
smart solution by Pragati!
santosh