0

我正在处理动态用户统计信息的签名。

这是我的代码:已更新

<?php
//Send a generated image to the browser
$config->Host = 'localhost';
$config->User = 'grpg';
$config->Pass = 'E8vspAcP';
$config->DB   = 'grpg_wp';;

$con = mysql_connect($config->Host,$config->User,$config->Pass);
if (!$con) die('<div class="errorbox">Nepavyko prisijungti prie duomenu bazes: '. mysql_error() .'</div>');

mysql_select_db($config->DB, $con);
$query = mysql_query("SELECT * FROM serverplayers WHERE id=1");
$showuser = mysql_fetch_assoc($query);
$user1 = $showuser['User'];
$user="$user1";  // or the value from your database
create_image($user);

function create_image($user)
{
    //Set the image width and height
    $width = 100;
    $height = 20;

    //Create the image resource
    $image = ImageCreate($width, $height);

    //We are making three colors, white, black and gray
    $white = ImageColorAllocate($image, 255, 255, 255);
    $black = ImageColorAllocate($image, 0, 0, 0);
    $grey = ImageColorAllocate($image, 204, 204, 204);

    //Make the background black
    ImageFill($image, 0, 0, $black);

    //Add randomly generated string in white to the image
    ImageString($image, 3, 30, 3, "$user", $white);
    //Tell the browser what kind of file is come in
    header("Content-Type: image/jpeg");

    //Output the newly created image in jpeg format
    ImageJpeg($image);

    //Free up resources
    ImageDestroy($image);
}
?>

如果我改变这个:$pass = "$user";$pass = "erlis";的用户名显示没有问题。这是怎么回事?图像显示很好,但没有文字。无法弄清楚...

4

1 回答 1

3

$show['User'];不在该功能的范围内。您需要将其传递给您的函数

function create_image($user) 
{
  //.....
}

而且,在填充变量之后调用你的函数,而不是之前!

$user="test";  // or the value from your database
create_image($user);
于 2013-09-25T15:50:48.370 回答