Forum Moderators: coopster

Message Too Old, No Replies

Redirecting

         

dbarasuk

8:01 pm on Aug 12, 2009 (gmt 0)

10+ Year Member



Hello

If you make a post on this site, if the thread is accepted, there is new page that appears and informs you that the thread was accepted followed by the message: Now redirecting...
(The message remains for some second before redirecting you)

By which PHP function can i do the same, pls?

Thanks

CyBerAliEn

11:05 pm on Aug 12, 2009 (gmt 0)

10+ Year Member



That is not done directly by PHP. PHP is a server-side language; it processes everything and then passes it on to the user. To continue "interacting" on the user-side, you need a client-side language: Javascript.

The following code demonstrates how you could force the page to redirect after 5 seconds to another page...


<script type="text/javascript">
var url = '/new-page-to-go-to.html';
setTimeout("window.location = '"+url+"';",5000);
</script>

This function sets off an action (changing the page) after 5000 milliseconds (5 seconds). Just put this code anywhere in your page. I'd recommend somewhere near the bottom (my preference). Some might recommend putting this in the "onLoad" event; but I avoid that (it won't get triggered until the page completely finishes loading).

You could, if desired, use PHP to "build out" this code automatically for you.

Some sites might also use the HTML "meta refresh" method. But I'd advise using Javascript (my preference). Just remember to include a standard link on the page (in case Javascript is disabled).

Good luck!

rocknbil

4:53 pm on Aug 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would use meta-refresh as it's widely supported, and will not fail if Javascript is disabled.

Per "this website":

<META http-equiv="refresh" content="5;URL=thread#message number">