スクリプトのこの部分があります。このスクリプトの前に、ページのコンテンツを返す curl 関数があります。preg_match を使用して、これらの値を取得しています。問題は、imagecreate スクリプトまたはそれに関連するものにあります。
スクリプトは次のとおりです。
<?php
ob_start();
$user = "username";
$pw = "pass";
$ne_ki = 1;
$postfields = "name=".$id."&pass=".$pw."&ne_ki=".$ne_ki;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0); // Get the header
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, "http://domain.tld/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'C:\AppServ\www\curl\cookies.txt');
curl_setopt($ch, CURLOPT_URL, 'http://domain.tld/profile.php?id='.$_GET['id']);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$data2 = curl_exec($ch);
curl_close($ch);
preg_match_all ("/<div class=\"profil_jobb_masodik2\">([^`]*?)<\/div>/", $data2,$matches);
preg_match_all ("/<div class=\"lista_mini_fej\">([^`]*?)<\/div>/", $data2, $matches2);
preg_match_all ("/<nobr>([^`]*?)<\/nobr>/", $data2, $matches3);
$string = preg_match("/\([0-9]+\)/", $matches2[0][0], $strend);
$HTML = '';
$HTML .= "DATA1: ".$matches3[0][0]."<br />";
$HTML .= "DATA2: ".$matches[1][0]."<br />";
$HTML .= "DATA3: ".$matches[1][1]."<br />";
$HTML .= "DATA4: ".$matches[1][2]."<br />";
$HTML .= "DATA5: ".$matches[1][3]."<br />";
$HTML .= "DATA6: ".$matches[1][4]."<br />";
$HTML .= "DATA7: ".$matches[1][5]."<br />";
$HTML .= "DATA8: ".$matches[1][6]."<br />";
$HTML .= "DATA9: ".$matches[1][7]."<br />";
if (!empty($strend[0]))
$HTML .= "DATA10: ".$strend[0]."<br />";
$text = $HTML;
if(empty($text))
fatal_error('Error: Text not properly formatted.') ;
// customizable variables
$font_file = 'ambient.ttf';
$font_size = 23 ; // font size in pts
$font_color = '#ffffff' ;
$image_file = 'bb.jpeg';
// x and y for the bottom right of the text
// so it expands like right aligned text
$x_finalpos = 227;
$y_finalpos = 103;
// trust me for now...in PNG out PNG
$mime_type = 'image/png' ;
$extension = '.png' ;
$s_end_buffer_size = 4096 ;
// check for GD support
if(!function_exists('ImageCreate'))
fatal_error('Error: Server does not support PHP image generation') ;
// check font availability;
if(!is_readable($font_file)) {
fatal_error('Error: The server is missing the specified font.') ;
}
// create and measure the text
$font_rgb = hex_to_rgb($font_color) ;
$box = @ImageTTFBBox($font_size,0,$font_file,$text) ;
$text_width = abs($box[2]-$box[0]);
$text_height = abs($box[5]-$box[3]);
$image = imagecreatefrompng($image_file);
if(!$image || !$box)
{
fatal_error('Error: The server could not create this image.') ;
}
// allocate colors and measure final text position
$font_color = ImageColorAllocate($image,$font_rgb['red'],$font_rgb['green'],$font_rgb['blue']) ;
$image_width = imagesx($image);
$put_text_x = $image_width - $text_width - ($image_width - $x_finalpos);
$put_text_y = $y_finalpos;
// Write the text
imagettftext($image, $font_size, 0, $put_text_x, $put_text_y, $font_color, $font_file, $text);
header('Content-type: ' . $mime_type) ;
ImagePNG($image) ;
ImageDestroy($image) ;
exit ;
/*
attempt to create an image containing the error message given.
if this works, the image is sent to the browser. if not, an error
is logged, and passed back to the browser as a 500 code instead.
*/
function fatal_error($message)
{
// send an image
if(function_exists('ImageCreate'))
{
$width = ImageFontWidth(5) * strlen($message) + 10 ;
$height = ImageFontHeight(5) + 10 ;
if($image = ImageCreate($width,$height))
{
$background = ImageColorAllocate($image,255,255,255) ;
$text_color = ImageColorAllocate($image,0,0,0) ;
ImageString($image,5,5,5,$message,$text_color) ;
header('Content-type: image/png') ;
ImagePNG($image) ;
ImageDestroy($image) ;
// This is line 197
exit ;
}
}
}
/*
decode an HTML hex-code into an array of R,G, and B values.
accepts these formats: (case insensitive) #ffffff, ffffff, #fff, fff
*/
function hex_to_rgb($hex) {
// remove '#'
if(substr($hex,0,1) == '#')
$hex = substr($hex,1) ;
// expand short form ('fff') color to long form ('ffffff')
if(strlen($hex) == 3) {
$hex = substr($hex,0,1) . substr($hex,0,1) .
substr($hex,1,1) . substr($hex,1,1) .
substr($hex,2,1) . substr($hex,2,1) ;
}
if(strlen($hex) != 6)
fatal_error('Error: Invalid color "'.$hex.'"') ;
// convert from hexidecimal number systems
$rgb['red'] = hexdec(substr($hex,0,2)) ;
$rgb['green'] = hexdec(substr($hex,2,2)) ;
$rgb['blue'] = hexdec(substr($hex,4,2)) ;
return $rgb ;
}
?>
行 197 はコメントでマークされています。エラーは次のとおりです。
警告: ヘッダー情報を変更できません - 197 行目の C:\AppServ\www\curl\index.php の (C:\AppServ\www\curl\index.php:1 で出力が開始された) によって既に送信されたヘッダー
何が問題ですか?