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;
}
}
Link to comment
Share on other sites

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.

Edited by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.