0

I used to use a script to change the text on an image via update form.

It worked perfectly at first while I was on a shared host with all modules pre-installed.

I moved to a vps where I had to install everything myself and now the script no longer works.

The php page is able to be displayed but when I update, the text does not show up like it used to.

Here is an example of the page on the shared host that still works: http://nyanpuffle.com/auntarctic/ Password is 1234

Here is an example of the page on the vps that does not work: http://www.clubpenguincheatsy.com/cptrackers/auntarctic/ Password is 1234

Here is a copy of the coding used:

<TITLE>Tracker</TITLE>
<body bgcolor="#4b7bb2">
<font face="arial">
<center>
<?php
$submit = $_POST['submit']; // Gets If It has been Submitted
if($submit){ // If submitted do this.
$password = $_POST['password']; // Get the password they submitted
$status = $_POST['status']; // Get the status they submitted
$server = $_POST['server']; // Get the server they submitted
$room = $_POST['room']; // Get the room they submitted
//Now We Secure it.
if($password == "1234"){
//Now We Generate the image and stuff.
$im = imagecreatefrompng("in.png");
// Make RGB Colour For Writing
$colour = imagecolorallocate($im, 255, 255, 255); // I want mine in red(This is black). So I am just
//Gonna find out the rgb code
$font = 'BurbankBigRegular-Bold.ttf'; // 
//This ^ Is our font, It has to be the exact name and in the right folder.
//Draw Text
imagettftext($im, 20, 0, 100, 68, $colour, $font, $status);
imagettftext($im, 20, 0, 95, 95, $colour, $font, $server);
imagettftext($im, 20, 0, 85, 127, $colour, $font, $room);
//Create Image
imagepng($im,'out.png');
// Destroy - Save Server Resources
imagedestroy($im);
echo "<b> Updated! </b>";
}else
{
echo "<p><b>Incorrect Password!</b></p>";
}
}
//This form remebers what they put, so they dont have to keep typing it in.
// $_SERVER['PHP_SELF'] Means Get this document to submit to.
// If you know html this will be familiar.
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" />
<p>Password: <input type="password"  name="password" id="password" value="<?php echo $_POST['password']; ?>"/></p>
<p>Status: <select name="status"> <option value="">Select...</option>
  <option value="Online"> Online</option>
  <option value="Offline"> Offline</option>
  <option value="Tracking..."> Tracking</option>
</select>
</p>
<p>Server: <input type="text" id="server"  name="server" value="<?php echo $_POST['server']; ?>"/></p>
<p>Room: <input type="text" id="room" name="room" value="<?php echo $_POST['room']; ?>"/></p>
<p><input type="submit" id="submit" name="submit"/></p>
</form>

<p>Tracker:</p>
<p><img src="out.png" alt="Tracker" /></P>

<a href="http://ClubPenguincheatsy.com/cptrackers"s>Back to Tracker Dashbaord</a>
</center>

The VPS is ran on Ubuntu and I have PHP,MYSQL, and Apache installed.

4

2 回答 2

0

您的原始代码会在所有变量上引发Undefined variable:错误,您应该在使用它们之前始终设置变量,这包括 $_POST 变量,您应该error_reporting(E_ALL)在开发时启用错误报告,然后error_reporting(0)在上传到实时站点时也进行更改,然后您会看到错误停止图像的处理/更新。

我已经通过一些更改修复了您的代码:

<?php 
header("Cache-Control: no-cache, must-revalidate"); //remind the browser not to cache the image
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
error_reporting(E_ALL); //Change to 0 when live
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Tracker</title>
  </head>

  <body bgcolor="#4b7bb2">
   <font face="arial">
   <center>
 <?php
    $password=''; //pre-set thos vars
    $status='';
    $server='';
    $room='';

    if(isset($_POST['submit'])){
        $password = $_POST['password'];
        if($password == "1234"){
            $status = $_POST['status'];
            $server = $_POST['server'];
            $room = $_POST['room'];

            $im = imagecreatefrompng("in.png");
            $colour = imagecolorallocate($im, 255, 255, 255);
            $font = 'BurbankBigRegular-Bold.ttf'; //

            imagettftext($im, 20, 0, 100, 68, $colour, $font, $status);
            imagettftext($im, 20, 0, 95, 95, $colour, $font, $server);
            imagettftext($im, 20, 0, 85, 127, $colour, $font, $room);
            imagepng($im,'out.png');
            imagedestroy($im);
            $result="<b> Updated! </b>";
        }else{
            $result="<p><b>Incorrect Password!</b></p>";
        }
    }
    echo (isset($result))?$result:'';
    ?>
    <form action="" method="POST" />
    <p>Password: <input type="password"  name="password" value="<?php echo htmlentities($password); ?>"/></p>

    <p>Status: <select name="status">
    <option value="">Select...</option>
    <?php 
    echo "<option value=\"Online\""; if($status=='Online'){ echo" selected=\"selected\"";} echo"> Online</option>\n";
    echo "<option value=\"Offline\""; if($status=='Offline'){ echo" selected=\"selected\"";} echo"> Offline</option>\n";
    echo "<option value=\"Tracking...\""; if($status=='Tracking...'){ echo" selected=\"selected\"";} echo"> Tracking</option>\n";
    ?>
    </select>
    </p>

    <p>Server: <input type="text" name="server" value="<?php echo htmlentities($server); ?>"/></p>
    <p>Room: <input type="text" name="room" value="<?php echo htmlentities($room); ?>"/></p>
    <p><input type="submit" name="submit"/></p>
    </form>

    <p>Tracker:</p>
    <p><img src="out.png" alt="Tracker" /></P>

    <a href="http://ClubPenguincheatsy.com/cptrackers"s>Back to Tracker Dashbaord</a>
</center>
</body>
</html>

注意表格中的htmlentities()& 不使用$_SERVER['PHP_SELF']

编辑: 取自http://php.net/manual/en/function.imagettftext.php

您希望使用的 TrueType 字体的路径。

根据 PHP 使用的 GD 库版本,当 fontfile 不以前导 / 开头时,.ttf 将附加到文件名,并且库将尝试沿着库定义的字体路径搜索该文件名。

当使用低于 2.0.18 的 GD 库版本时,使用空格字符而不是分号作为不同字体文件的“路径分隔符”。无意使用此功能将导致警告消息:警告:无法找到/打开字体。对于这些受影响的版本,唯一的解决方案是将字体移动到不包含空格的路径。

在许多情况下,字体与使用它的脚本位于同一目录中,以下技巧将缓解任何包含问题。

<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'BurbankBigRegular-Bold';
?>
于 2011-08-01T02:05:46.850 回答
0

$font = 'BurbankBigRegular-Bold.ttf';

用。。。来代替 :

定义(“_DOC_ROOT”,目录名(__FILE__)。“/”);
$font = _DOC_ROOT.'dir_u_know/dir_u_know/BurbankBigRegular-Bold.ttf';

于 2017-10-10T08:42:15.480 回答