0

I have an old image captcha generator written in PHP4 that i need to convert to PHP5 Any suggestions for what I need to change to get it to start working? The main error I'm getting reads "Resource interpreted as Image but transferred with MIME type text/html" Which I already told it to have a MIME type of image throough the code below when I said header('Content-type: image/jpeg');

<?php
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);

session_start(); 

$alphanum  = "ABGKLMNPRSTUXZ"; 
$rand = substr(str_shuffle($alphanum), 0, 5); 
$image = imagecreatetruecolor(65,25);
$background = imagecolorallocate($image, 255, 255, 255);
$border = imagecolorallocate($image, 128, 128, 128);
$colors[] = imagecolorallocate($image, 128, 64, 192);
$colors[] = imagecolorallocate($image, 192, 64, 128);
$colors[] = imagecolorallocate($image, 108, 192, 64);

imagefilledrectangle($image, 1, 1, 65 - 2, 25 - 2, $background);
imagerectangle($image, 0, 0, 65 - 1, 25 - 1, $border);

for ($i = 0; $i < 5; $i++){
    $x1 = rand(0, 65 - 5);
    $y1 = rand(0, 25 - 5);
    $x2 = $x1 - 4 + rand(2, 8);
    $y2 = $y1 - 4 + rand(2, 8);
    imageline($image, $x1, $y1, $x2, $y2,$colors[rand(0, count($colors) - 1)]);
}

$textColor = imagecolorallocate ($image, 30, 30, 30); 

imagestring ($image, 8, rand(8,10), rand(1,8),  $rand, $textColor); 

$_SESSION['image_random_value'] = md5($rand); 

header("Expires: Mon, 26 Jul 1998 06:00:00 GMT");  
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  
header("Cache-Control: no-store, no-cache, must-revalidate");  
header("Cache-Control: post-check=0, pre-check=0", false);  
header("Pragma: no-cache");
header('Content-type: image/jpeg');

imagejpeg($image); 
imagedestroy($image); 
?>

This image loads into the page here if its at all helpful:



    
    function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit)
    field.value = field.value.substring(0, maxlimit);
    else
    countfield.value = maxlimit - field.value.length;
    }
    function form_visible(){
    var el = document.getElementById('sf');
    if(el.style.display == 'inline'){
    el.style.display = 'none';
    }else{
    el.style.display = 'inline';
    }
    }
    var shows = 0;
    var lc;
    var i;
    var image;
    var ny;
    function show(star_img,rnid) 
    {
    if (shows){
    if(rnid==lc){
    return;
    }
    }

    for (i=1; i");
    for (var i=1; i");
    }
    document.write("Please Select");
    }
    
     $value) {
    ${$key} = $value;
    } 
    foreach($_POST AS $key => $value) {
    ${$key} = $value;
    } 

    $db=mysql_connect($db_host,$database_user,$database_pass) or die("MySQL Error: Unable to connect to database please check that you have provided the correct 
  • Database Login username
  • Database Login Password"); mysql_select_db($db_name,$db)or die("MySQL Error: Unable to select database please check that you have provided the correct
  • Database name"); echo "


    "; $day =date("D d"); $month =date("M"); $year =date("Y"); $dt="$year-$month-$day"; $ent=mysql_query("SELECT * FROM ez_ccomment_opt"); $rowi=@mysql_fetch_array($ent); if($do=="do_sign" && $id=="$mid"){ if ($comment !="" && $email !="" && $name !="" && $rating!=""){ if(md5($_POST['security']) == $_SESSION['image_random_value']){ $comment = str_replace ("","&gt", $comment); $name = str_replace ("","&gt", $name); $email = str_replace ("","&gt", $email); $website = str_replace ("", $comment); $comment = str_replace ("

    ", "
    ", $comment); $name = stripslashes ($name); $comment = stripslashes ($comment); $lis="0"; if($rowi[filter]=="y"){ $user=file("badwords.txt"); for($x=0;$xPlease enter valid security image."; } }else{ $w="1"; echo "Please fill in the required fields.";} } ob_start(); echo ""; echo "Rating*"; ?> showform(1); "; echo "Comments* Name* Email* (Will not be shown) Security Image*make sure to type security image in ALL CAPITAL characters!
    * = Required


    "; echo ""; ob_end_flush(); if($w=="1"){ ?> var el = document.getElementById('sf'); el.style.display = 'inline'; "; $list = ("SELECT * FROM ez_ccomment WHERE status='confirmed' AND ccid='$id' ORDER BY op DESC"); $row_num1= @mysql_num_rows(mysql_query($list)); $list_per_page=$rowi['limit_pp']; if($row_num1>0){ echo "Comments"; }else{ echo "No ratings yet. Be the first to add a rating!"; } if($start==""){ $start=1; } if($start==""||$start==1){ $sfrom=0; }else{ $sfrom=(($start-1)*$list_per_page); } $end=$list_per_page; $gr=0; $list.= (" LIMIT $sfrom,$end"); $blist=(mysql_query($list)); while($row=@mysql_fetch_array($blist)){ if(substr_count($row[email],"@")==1){ $name="$row[name]"; }else{ $name="$row[name]"; } $messag=$row[message]; $messag=wordwrap($messag, 55, "\n", 1); $row[rating]=round($row[rating],2); if ($row[rating] == 5) { $star = "images/5star.gif" ; $pk="5 - Excellent!"; } if ($row[rating]>=1 && $row[rating]=2 && $row[rating]=3 && $row[rating]= 4 && $row[rating]= 5) { $star = "images/5star.gif" ; $pk="5 - Excellent!"; } if ($row[rating] $messag$row[name], $row[date]"; $gr+=1; } $list_per_page=$rowi['limit_pp']; echo ""; if($start==""){ $start=1; } if($start==""||$start==1){ $sfrom=0; }else{ $sfrom=(($start-1)*$list_per_page); } $end=$list_per_page; if ($row_num1>$list_per_page){ $no_of_page=$row_num1/$list_per_page; $no_page=explode(".",$no_of_page); if($no_page[1]>0){ $no_of_page+=1; } echo ""; echo ""; if($start > 1){ $s=$start-1; echo "Previous"; } echo ""; $last=round($no_of_page,0); for($i=1;$i$i "; }else{ echo " $i "; } }else{ if($i>$start+3){ if($once==""){ echo " ....... $last"; } $once="yes"; }elseif($i0){ echo "1 ....... "; } $tonce="yes"; }else{ if($i!=$start){ echo " $i "; }else{ echo " $i "; } } } } echo ""; if($start Next"; }elseif($start>=$i){ $next = ""; } echo "$next"; } echo ""; ?>
  • Magisch
    • 7,312
    • 9
    • 36
    • 52
    J Grover
    • 1,029
    • 1
    • 9
    • 14
    • Which PHP 5 version? I switched the tag to current PHP version, please review I luckily do not know which PHP version godaddy has. Also please properly indent your code and see the manual how to migrate from one PHP version to another. Additionally log errors to the highest level and track your error log. That will show you the issue immediately. – hakre Oct 06 '12 at 12:53
    • Thanks hakre. I will update my error log settings. This was third party script i bought hence why it has sloppy indenting. oso's answer below seemed to fix the issue. I needed to change $HTTP_GET_VARS for $_GET and $HTTP_POST_VARS for $_POST to work with PHP5. – J Grover Oct 06 '12 at 15:07

    1 Answers1

    1

    In that code, just change $HTTP_GET_VARS for $_GET and $HTTP_POST_VARS for $_POST

    extract($_GET);
    extract($_POST);
    

    I tried it and it works.

    Eduardo Reveles
    • 2,155
    • 17
    • 14