Invoke a script without the user clicking a link

Hi,
I’m sorry if this gets posted twice. The captcha keeps failing and then tells me I already posted.

I am a PHP newbie. So, thanks in advance for your patience if this has already been answered elsewhere. I searched, but could not locate a solution.

I have implemented the following PHP code generously provided by “Ask Michael Komarov.” It sequentially rotates content on my page when a visitor clicks the link. I want to sequentially rotate the content on a timed interval. I think I need to use a while(true) loop that include a sleep(10), but I have no idea how to trigger the PHP script the way the href link does.

I can move the print function anywhere on the page. Does the loop need to be inside this if structure, or somewhere else on the page?

I’m sure it’s simple, but it’s a mystery to me. Thanks for the advice.

[php]

<?php if (isset($content_rotation_list) && is_array($content_rotation_list) && count($content_rotation_list) > 0) { $next = isset($_GET["next"])? intval($_GET["next"]): 0; if (++$next >= count($content_rotation_list)) $next = 0; include($content_rotation_list[$next]); print "Refresh"; } ?>

[/php]

What if you just printed a meta refresh?

e.g.

[php]echo “<meta http-equiv=“refresh” content=“10;URL=’” . $_SERVER[‘PHP_SELF’] . “?next=” . $next . “’”>”;[/php]

That does it. Thanks.

Expecting the boss to ask: “Can the visitor pause the rotation while they read the content?”

I would imagine that involves a button below the content to perhaps change the state of a variable - either the value of the reload delay or a do-wile condition.

Thanks again.

If you want to pause I think you would need to use JavaScript instead of meta refresh

Sponsor our Newsletter | Privacy Policy | Terms of Service