Forum Moderators: coopster

Message Too Old, No Replies

PHP inside a frame, different content with every page reload?

I use a PHP script which selects an URL randomly and displays it.

         

chaosas

5:57 am on Oct 5, 2008 (gmt 0)

10+ Year Member



Hello,
I'm using a script which selects an URL randomly and sends the visitor to it using a 302 redirect. That's a so called URL rotator.

Now I decided to put it into a frame, so instead of:

header("Location: $url");

I simply entered

echo '<html>
<head>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
</head>
<frameset border=0 rows="100%,*" frameborder="no" margintop=0 marginleft=0 marginright=0 marginbottom=0>
<frame SRC="',$url,'" scrolling=auto frameborder="no" border=0 noresize>
<frame topmargin="0" marginwidth=0 scrolling=no marginheight=0 frameborder="no" border=0 noresize>
<body>
</body>
</frameset></html>';

It does work, but my problem is that it shows the same site to the same visitor, no matter how many times he refreshes the page or clears browser cache. It does show a different site if you open it in a new tab/click a link leading to it/etc.

For a specific reason I'd like it to show a different website everytime someone refreshes the page (or at least display same site for several seconds, not forever like it is now). How can I achieve this?

I tried disabling eaccelerator with php.ini (shared hosting in this case), but there weren't any effect.

I think it might have something to do with caching, but I'm afraid I don't know much PHP at all. As far as I can tell it doesn't set any cookies, nor does it use sessions.

Thanks.

chaosas

5:58 am on Oct 5, 2008 (gmt 0)

10+ Year Member



Oh sorry, figured you might need to see the whole thing:


<?php
if (phpversion() <= '4.0.6') {$_SERVER=$HTTP_SERVER_VARS;$_POST=$HTTP_POST_VARS;$_GET=$HTTP_GET_VARS;$_ENV=$HTTP_ENV_VARS;$_COOKIE=$HTTP_COOKIE_VARS;}
include($inc_file);
if (!$_SERVER['QUERY_STRING'])
{
$urls = file($url_file);
srand((double)microtime()*1000000);
$url = '';
$cnt = 0;
while (trim($url) == '' && $cnt < 5)
{
$url = trim($urls[rand(0, sizeof($urls) - 1)]);
$cnt++;
if ($cnt == 3) optimizeURLS();
}
if ($url == '')
{
echo("Could not find a URL to display. Please add one first.");
exit;
}
header("Location: $url");
exit;
}
?>

The redirection part was replaced with an iframe.
The code for admin area follows after this, but I didn't think it would be needed.