get_random.phtml not working with IE 7--HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

get_random.phtml not working with IE 7--HELP!

Post by eabigelow »

Hi--

I am using the following PHP code to retrieve a random text entry from a msg.dat file, but the code does not seem to work in IE 7 (but does work in FireFox, Mozilla, and Safari). It will generate two entries at random, and then it will continue to show the second entry without randomly picking any more. The code is:

<?php

srand((double)microtime()*1000000);
$filename="msg.dat";
$message=file($filename);
$select=rand(0, count($message)+1);

$msg = "msg=$message[$select]";
echo "$msg";

?>

Does anyone have any idea of why this is happening, and even better, how to fix it? Many, many thanks for any help!!!!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: get_random.phtml not working with IE 7--HELP!

Post by onion2k »

I imagine IE7 is caching the page. Try sticking something like this at the top:

Code: Select all

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: get_random.phtml not working with IE 7--HELP!

Post by eabigelow »

Hi--

Thanks very much for your quick reply--

Just to make sure (I am really new at this!). The beginning of the file should look like this?

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

OR do I leave out the words "header"?

Again, many thanks!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: get_random.phtml not working with IE 7--HELP!

Post by onion2k »

You could always try both and see what happens.
eabigelow
Forum Newbie
Posts: 16
Joined: Thu Apr 24, 2008 7:06 am

Re: get_random.phtml not working with IE 7--HELP!

Post by eabigelow »

OK, thanks for all your help! I appreciate it!
Post Reply