Jump to content

php code not working on godaddy hosting but working fine on linux vps


ShivaGupta

Recommended Posts

i dont understand what is wrong plz help me.

here is code

$name = "img/".rand(1,9999999).".png";
$myFile = $name;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $html;
fwrite($fh, $stringData);
fclose($fh);
$file=$name;
$fst=file_get_contents($file);
$im=imagecreatefromstring($fst);
imagefilter($im, IMG_FILTER_GRAYSCALE);
imagefilter($im, IMG_FILTER_NEGATE);
//Convert to Grey Scale
for($i=0;$i<123;$i++){
for($j=0;$j<50;$j++){
$px=imagecolorat($im,$i,$j);
if($px<0x303030){
imagesetpixel($im,$i,$j,0);
}else{
imagesetpixel($im,$i,$j,0xffffff);
}
}
}
$database = unserialize(@file_get_contents("db.txt"));
if($database === false) $database = array();
// modify the database if needed
if($_SERVER['REQUEST_METHOD'] == 'POST'){
	if($_POST['submit'] == 'Add')
		$database[$_POST['ident']] = substr($_POST['letter'], 0, 1);
	if($_POST['submit'] == 'Del')
		unset($database[$_POST['ident']]);
	if($fh = @fopen('db111.txt', 'w+')){
		fwrite($fh, serialize($database));
		fclose($fh);
}
}else{
$newimage = true;
}
$width   = 130;
$height  = 40;
$captcha_gridstart   =1;
$captcha_gridspace   =2;
$letters = findletters($im, $width, $height, $captcha_gridstart, $captcha_gridspace);
$count   = count($letters);
$cellw   = ($count > 0) ? intval(100 / $count) : 0;
//dispeckle the image and GET co-ordinates of the characters of captcha image and return them. 
function findletters($image, $width, $height, $gridstart, $gridspace){
	$offsets  = array(); $o = 0;
	$atstartx = true;
	for($x = 0; $x < $width; $x++){
		$blankx = true;
		for($y = 0; $y < $height; $y++){
			if(imagecolorat($image, $x, $y) == 0){
				$blankx = false;
				break;
			}
		}
		if(!$blankx && $atstartx){
			$offsets[$o]['startx'] = $x;
			$atstartx = !$atstartx;
		}else if($blankx && !$atstartx){
			$offsets[$o]['endx']   = $x;
			$atstartx = !$atstartx;
			$o++;
		}
	}
	$count = $o;
	for($o = 0; $o < $count; $o++){
		for($y = 0; $y < $height; $y++){
			$blanky = true;
			for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){
				if(imagecolorat($image, $x, $y) == 0){
					$blanky = false;
					break;
				}
			}
			if(!$blanky){
				$offsets[$o]['starty'] = $y;
				break;
			}
		}
		for($y = $height-1; $y > $offsets[$o]['starty']; $y--){
			$blanky = true;
			for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){
				if(imagecolorat($image, $x, $y) == 0){
					$blanky = false;
					break;
				}
			}
			if(!$blanky){
				$offsets[$o]['endy'] = $y;
				break;
			}
		}
	}
	for($o = 0; $o < $count; $o++){
		$offsets[$o]['ident'] = "";
		for($x = $offsets[$o]['startx'] + $gridstart; $x < $offsets[$o]['endx']; $x += $gridspace){
			for($y = $offsets[$o]['starty'] + $gridstart; $y < $offsets[$o]['endy']; $y += $gridspace){
				$offsets[$o]['ident'] .= ((imagecolorat($image, $x, $y) == 0) ? "0" : "1");
				#echo $offsets[$o]['ident'].'<br>';
			}
		}
	}
	return $offsets;
}
$a="";
foreach($letters as $letter){
$asciiletter = $database[$letter['ident']];
if(!empty($asciiletter)) {
$a.=$asciiletter;
}
}

What IS wrong?  You don't give us any reason to suspect anything is wrong with this code.  Do you have messages or results of any kind?  Put some echo statements in the code to see what is happening.

 

PS - Turn on PHP error checking to see if you have something in your code that doesn't work in your new php environment.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.