0

好的,我有一个制作签名的网站。但是因为一些头文件问题我不得不把它放在另一个文件中并使用echo。这是代码:

<h1>Create your European Trucking signatures</h1>
<?php
echo '<img src="SigGen.php?player=$Playername&score=$Score&money=$Money" />';
?>
</div>

但它显示了一个破碎的图像。但是当我转到 SigGen.php 本身时,它确实显示如下: http
://european-trucking.com/SigGen.php?player_name=Thimo 这是 SigGen 的代码:

<?  
/* 
***Made by: Nodroz*** 
*** Enjoy your signatures! *** 
*/ 

$username="10528_Thimo"; //Your MySQL Username. 
$password="*********"; // Your MySQL Pass. 
$database="10528_Thimo"; // Your MySQL database. 
$host="95.211.***.***"; // Your MySQL host. This is "localhost" or the IP specified by your hosting company. 

$player_name=$_GET['player_name']; // This gets the player his name from the previous page. 

/* Next, we will make a connection to the mysql.  
If it can't connect, it'll print on the screen: Unable to select database. Be sure the databasename exists and online is. */ 

mysql_connect($host,$username,$password); // Connection to the database. 
@mysql_select_db($database) or die( "Unable to select database. Be sure the databasename exists and online is."); //Selection of the database. If it can't read the database, it'll give an error. 

/* To protect MySQL injection. */ 
$player_name = stripslashes($player_name); 
$player_name = mysql_real_escape_string($player_name); 



$query="SELECT * FROM Users WHERE Name='$player_name'"; // Gets all the information about the player. 
$result=mysql_query($query); 
$i=mysql_num_rows($result); // Here we are counting how many rows this result gives us. 

/* We will now put the player's information into variables so we can use them more easily. */ 
/* DON'T FORGET: The names should be exact the same as in your mysql db.*/ 

if ($i == 1) // If the user has been correct, then it'll give us 1 row. If its 1 row, then it'll proceed with the code. 
{ 

    $Playername=mysql_result($result,0,"Name"); // Gets the username of the player and put it in the variable $Playername. 
    $Money=mysql_result($result,0,"Money"); // Gets the money of the player and put it in the variable $Money. 
    $Score=mysql_result($result,0,"Score"); // Gets the score of the player and put it in the variable $Score. 


    // Creating of the .png image.  
    header('Content-Type: image/png;'); // Don't touch this. We use this to tell the script we're working with an image. 
    $im = @imagecreatefrompng('PlayerSig.png') or die("Cannot select the correct image. Please contact the webmaster."); // Don't forget to put your picture there. Eg: playersig.png 
    $text_color = imagecolorallocate($im, 000,000,000); // RED, GREEN, BLUE --> Go to www.colorpicker.com, select a nice color, copy the R/G/B letters provided by colorpicker and put them here. 
    $text_username = "$Playername"; // This gets the information: player name to be showed in the picture. 
    $text_score = "$Score"; // Same as above but with score. 
    $text_money = "$Money"; // Same as above but with money. 
    $font = 'myfont.ttf'; //Upload your custom font to the directory where this file is placed. Then change the name here. 
    /* USAGE OF THE imagettftext: First ($im) shouldn't be changed. (16) is the text-size. (0) is the angle of your text. Change it, and you'll see what's going on. (20) is de X-coordinate of the text. 
    (36) is the Y-coordinate of the text. */ 
    imagettftext($im, 16, 0, 5, 20, $text_color, $font, $text_username); // Prints the username in the picture.  
    imagettftext($im, 16, 0, 5, 40, $text_color, $font, "Score:");
    imagettftext($im, 16, 0, 72, 40, $text_color, $font, $text_score); // Prints the score in the picture. 
    imagettftext($im, 16, 0, 5, 60, $text_color, $font, "Money:");
    imagettftext($im, 16, 0, 72, 60, $text_color, $font, $text_money); // Prints the money in the picture. 
    imagepng($im); 
    imagedestroy($im);  
} else echo('Username is not in our database. Please try again.'); // If the username doesn't exist (so the row is 0) then it'll give en error. 

mysql_close(); 

?>

任何人都知道为什么它不使用回声显示为图像?

4

2 回答 2

6

我认为问题是你不能像这样在字符串中使用变量名:

这行不通

echo 'Hi $userName';

这将起作用

echo "Hi $userName";

所以你的线:

echo '<img src="SigGen.php?player=$Playername&score=$Score&money=$Money" />';

需要改为:

echo "<img src='SigGen.php?player=$Playername&score=$Score&money=$Money' />";
于 2013-07-02T06:08:02.523 回答
0

试试这个...

<?php echo '<img src="SigGen.php?player='.$Playername.'&score='.$Score.'&money='.$Money.'" />'; ?>

使用 echo 的串联功能将变量正确附加到图像链接

于 2013-07-02T06:53:01.757 回答