Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

PHP link rotating script

$
0
0

I have this PHP link rotating script, it works pretty fine...
when I run the script it redirect to:
link1.com
link2.com
link3.com
.... and so on

but when I change the web browser or someone else runs it, it restart from the begging..

I mean that it redirect back to link1.com

 

the script use a link.txt file where the link list is stored
what I want is that when I run the script it redirect to 
link1.com
when I change the web browser or someone else runs it continue redirecting to next link and so on...(to link2.com)

 

Here's the PHP code:

<?php
	
	function redirect_to($link) {
		header("Location: {$link}");
		exit;
	}
		
	$links = file('links.txt');	
	
	while (!$links) {
		$links = file('links.txt');	
	}
	
	$links_count = count($links);	
	$one_month = 60 * 60 * 24 * 30;
	

		$index = $_COOKIE['link_index'] + 1;		
		setcookie('link_index', $index, time() + $one_month);		
		
		if ($index == $links_count) {
			setcookie('link_index', 0, time() + $one_month);		
			$index = 0;
		}
	
	redirect_to($links[$index]);
	
?>

 Please help me solve this issue

 

Thanks


Viewing all articles
Browse latest Browse all 13200

Trending Articles