Simple text link rotator?

hi 00CivicEX, to clarify ... i create and just place a list of urls in the urlrotator.txt file ... but what do i do with the pos.txt file? thanks!

You will need to create the urlrotator.txt and postxt file and upload it to the directory the php file is located. Also make sure the folder it is in, is writeable, just change the permissions in your FTP Program. Hope this helps.
 
It can be blank, it is just to store the position. So it can read and know what the last link it used was. So when it is ran for the first time it will store its on values in it.
 
I am saying thanks because this will prove to be extremely useful.
 
I cant get this work so the php code I put in my http://mysite/index.php inbetween the header? Upload the 2 files and chmod the pos.txt file to write am I missing someting?
 
I found a script that works pretty good it redirects after a set amount of time much like the one above. If you find it helpful give me a thx,


Code:
<script type="text/javascript">
	
	var urls = new Array("http://www.google.com/", "http://www.yahoo.com/");
	
	function redirect()
	{
		window.location = urls[Math.floor(urls.length*Math.random())];
	}
	
	var temp = setInterval("redirect()", 3000);

</script>

3000 - you're redirected after 3 seconds.
 
That does it at random, not in sequence...like the one I posted above....just wanted to let people know that
 
PHP:
<?php
$linksfile ="urlrotator.txt";
$posfile = "pos.txt";
 
$links = file($linksfile);
$numlinks = count($linksfile);
 
$fp = fopen($posfile, 'r+') or die("Failed to open posfile");
flock($fp, LOCK_EX);
$num = fread($fp, 1024);
if($num<$numlinks-1) {
fwrite($fp, $num+1);
} else {
fwrite($fp, 0);
}
flock($fp, LOCK_UN);
fclose($fp);
 
header("Location: {$links[$num]}");
?>


I can't seem to get this code to work. I made the two files urlrotator.txt and pos.txt The folder is writable where the script and two files are placed. When I open the pos.txt file after trying to make the script work I see a 0 for every time I click the link it is writing to the pos.txt. It is not sending me to the URL in the urlrotator.txt. Do you know what I could be doing wrong?
 
Back
Top