Forum Moderators: coopster
text line 1
~
text line 2 and so on.
~
The following code as it is right now is only rotating between number 1 and 2. So the out put of this script is 1 one the first browser visit, and 2 on the next brower visit and then is starts over.
I need something that will also rotate my text lines I just listed above. Can someone please help me encorporate that into the following script? Thank you very much. The basics are there I just don't know how to finish it.
<?php
$maximum = 2;
$a = join ('', file ('content.txt'));
$c = split("~",$a);
$b = (isset($_COOKIE['e']) && intval($_COOKIE['e']) < $maximum)? intval($_COOKIE['e'])+1 : 1;
setcookie("e", $b, time()+60*60*24*30);
$include_file = "$b";
echo ($include_file);
?>
[edited by: Simone100 at 11:40 am (utc) on June 28, 2007]
Do the vaues have to be in a text file? Have you thought about storing them in an array [uk.php.net] and then shuffling [uk3.php.net] the array? That would seem to be a better way of doing things. I`m a little unclear of what you mean when you say 'rotate my text lines'?
If you mean just order them randomnly, I think an array would be better.
dc
So do I need to number each block in the array? If so, how?
Please let me know, thank you very much.
I don't believe I need a shuffle because it isn't a random selection unless for some reason you think it needs to stay.
This only returns Array . 1 and 2. Using the word "array" not whats in the array. I've read through the php manual, don't know how to number the array.
All I need is it to say "this is something 1" on first page load.
"This is whatever 2" on the next page load and so on, whatever text I put in the array.
Its counting up to the maximum number like it is supposed to be and then starting over. But its not associating the cookie countdown to the array numbers or the text associated with them.
So then I though maybe I needed an associative array to associate the cookie numbers to the array and this didn't work either.
<?php
$maximum=3;
$a = (isset($_COOKIE['e']) && intval($_COOKIE['e']) < $maximum)? intval($_COOKIE['e'])+1 : 1;
setcookie("e", $a, time()+60*60*24*30);
$this = array(array( 1 => 'test1'),
array( 2 => 'test2'),
array( 3 => 'test3'));
$include_file = "$a . $this";
echo($include_file);
?>
[edited by: Simone100 at 1:57 pm (utc) on July 1, 2007]
Wht you want is to check the cookie and then use an if statement so -
if ($_COOKIE['yourvalue'] == "value 1"){
print "message 1";
}
if ($_COOKIE['yourvalue'] == "value 2"){
print "message 2";
}
and so on
The only problem left is another problem I've had all along with opera and php. I asked others here before and no one knew the answer.
Opera won't read the new text on next page load like IE and Mozilla do.
So I tried putting the code above the headers and just this in the body. <?php echo $text[$a];?>
That didn't work. So I tried each of these that opera said I needed to quit cacheing before or after the title of the page:
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<meta http-equiv="Expires" CONTENT="Tue, 3 July 2007 14:25:27 GMT">
But none of that worked either. Anyone know how to get opera to reread php on a new page load when there is cookies? Thanks.