$go = $_REQUEST['go'];
include "cpLinksConfig.php";
/*
$data = "niki_bloghop";
$user = "niki_bloghop";
$pass = "wOb0ouW7QqZO";
$host = "localhost";
*/
if((empty($go))||($go == "home")) {
	$connection = @mysql_connect("$host", "$user", "$pass") or die("Couldn't connect today.");
	$db = @mysql_select_db($data, $connection) or die("Couldn't select database.");
	$getlinks ="SELECT * FROM maininfo LIMIT 0,1";
	$getMylinks = mysql_query($getlinks,$connection) or die("coundn't verify link database 1");
	while ($row = Mysql_fetch_array($getMylinks)) {
		$linkID = $row['ID'];
		$URL = $row['URL'];
		$count = $row['count'];
		
		}
	$newcount = ($count + 1);		
	$sql = "UPDATE maininfo SET count='$newcount' WHERE ID=$linkID";
	$result = @mysql_query($sql,$connection) or die("Couldn't update count.");
	mysql_close();
	header("Location: $URL");
}
else {
	$siteid = $_REQUEST['id'];
	$connection = @mysql_connect("$host", "$user", "$pass") or die("Couldn't connect today.");
	$db = @mysql_select_db($data, $connection) or die("Couldn't select database.");
if (!empty($siteid)) {
	//echo "TESTING: this is not an error, Jen is working on the code for just a moment.
 Thank you for your understanding.
Your site id is $siteid
 go is $go
";
	$getlinks ="SELECT * FROM hoppers WHERE ID = $siteid";
	$getMylinks = mysql_query($getlinks,$connection) or die("coundn't verify link database 1");
	$num_rows = mysql_num_rows($getMylinks);
}
else {
	$referrer = $HTTP_REFERER;
	$ref = split("/",$referrer);
	$ref1= $ref[2];
	
	//$ref2=ereg_replace("wordpress.com","",$ref1);
	
	$ref = "http://$ref1";
	
//	echo "TESTING: this is not an error, Jen is working on the code for just a moment.
 Thank you for your understanding.
You came from: $referrer and ref is $ref1 and ref2 is $ref2
 go is $go
";
	$getlinks ="SELECT * FROM hoppers WHERE url LIKE \"%$ref1%\"";
	$getMylinks = mysql_query($getlinks,$connection) or die("coundn't verify link database 1");
	$num_rows = mysql_num_rows($getMylinks);
}
	if(empty($num_rows)) {
		$getlinks ="SELECT * FROM maininfo LIMIT 0,1";
		$getMylinks = mysql_query($getlinks,$connection) or die("coundn't verify link database 1");
		while ($row = Mysql_fetch_array($getMylinks)) {
			$URL = $row['URL'];		
		}
		
		mysql_close();
		header("Location: $URL");
	}
	while ($row = Mysql_fetch_array($getMylinks)) {
		$linkID = $row['ID'];
		$clicks = $row['clicks'];		
		$newclick = ($clicks + 1);		
		$sql = "UPDATE hoppers SET clicks='$newclick' WHERE ID=$linkID";
		$result = @mysql_query($sql,$connection) or die("Couldn't update count.");
		//echo "site id is $linkID
";
		if ($go == "b") {
			$getlinks2 ="SELECT * FROM hoppers WHERE hide != 'Y' AND ID < $linkID AND display > '0' ORDER BY ID DESC LIMIT 1";
			//echo "go id prev
";
		}
		else {
			$getlinks2 ="SELECT * FROM hoppers WHERE hide != 'Y' AND ID > $linkID AND display > '0' ORDER BY ID ASC LIMIT 1";
			//echo "go id next and id is $linkID
";
		}
		$getMylinks2 = mysql_query($getlinks2,$connection) or die("coundn't verify link database 2");
		$num_rows = mysql_num_rows($getMylinks2);
		
//		echo "numsrows is $num_rows";
		if(empty($num_rows)) {
			if ($go == "b") {
				$getlinks2 ="SELECT * FROM hoppers WHERE hide != 'Y' AND display > '0' ORDER BY ID DESC LIMIT 0,1";
				
			}
			else {
				$getlinks2 ="SELECT * FROM hoppers WHERE hide != 'Y' AND display > '0' ORDER BY ID ASC LIMIT 0,1";
			//	echo "f";
			}
				
				$getMylinks2 = mysql_query($getlinks2,$connection) or die("coundn't verify link database 3");
			}
			
			while ($row = Mysql_fetch_array($getMylinks2)) {
				$url = $row['url'];
			}
			//$url = $ref;
			//echo "next url is $url";
			mysql_close();
	//	echo "