<html> <head> <title>My title here</title> </head> <h1>Signature configuration.</h1> <p>Hello and welcome to the image configuration page.<br /> Before you can make your signature, we need in-game name, exact as it is.</p> <form action="signature.php" method="get"> <!-- When you click the "send" button, this information will be send to the "signature.php" page. If you're using another php page, you need to change "signature.php" to the file you called it. --> Playername: <input type="text" name="player_name"><br> <!-- This is a little text box which will ask for you playername. --> <input type="Submit"> <!-- A "send" button. --> </form> </body> </html>
$player_name=$_GET['player_name']; // This gets the player his name from the previous page.
/* Let's start by configuring your mysql details. */
$username=""; //Your MySQL Username.
$password=""; // Your MySQL Pass.
$database=""; // Your MySQL database.
$host=""; // Your MySQL host. This is "localhost" or the IP specified by your hosting company.
/* 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.");
/* To protect MySQL injection. */
$player_name = stripslashes($player_name);
$player_name = mysql_real_escape_string($player_name);
$query="SELECT * FROM users WHERE Playername='$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,"Playername"); // 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.
/*****ADD PART 6 HERE ******/
} 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.
// 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('mypicture.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, 197,197,199); // 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, 20, 36, $text_color, $font, $text_username); // Prints the username in the picture.
imagettftext($im, 16, 0, 72, 69, $text_color, $font, $text_score); // Prints the score in the picture.
imagettftext($im, 16, 0, 72, 99, $text_color, $font, $text_money); // Prints the money in the picture.
imagepng($im);
imagedestroy($im);
mysql_close();
<?
/*
***Made by: Nodroz***
*** Enjoy your signatures! ***
*/
$username=""; //Your MySQL Username.
$password=""; // Your MySQL Pass.
$database=""; // Your MySQL database.
$host=""; // 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 Playername='$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,"Playername"); // 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;');
$im = @imagecreatefrompng('mypicture.png') or die("Cannot select the correct image. Please contact the webmaster."); // Don't forget to put your picture there.
$text_color = imagecolorallocate($im, 197,197,199); // 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 about player name to be showed in the picture.
$text_score = "$Score"; // Same as above ^^
$text_money = "$Money"; // Same as above ^^
$font = 'myfont.ttf'; //Upload your custum 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, 20, 36, $text_color, $font, $text_username); // Prints the username in the picture.
imagettftext($im, 16, 0, 72, 69, $text_color, $font, $text_score); // Prints the score in the picture.
imagettftext($im, 16, 0, 72, 99, $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();
?>
$query="SELECT * FROM users WHERE Playername='$player_name'";
$query="SELECT * FROM users WHERE Playername='$player_name' LIMIT 1";
PHP код:
PHP код:
|
This is a really sweet tutorial! Well done. Just out of interest. For servers that use INI file systems, could the PHP function parse_ini_file() be used, instead of connecting to a database? |
PHP код:
PHP код:
|
I suggest you to read whats "LIMIT 1" used for since for a while everyone here tends to reply saying it will freeze your server/host if you dont use it, when it doesnt happen and depends on the query you are executing, use a bit of common sense and re read the query again.
Select all from the table 'users' where the field 'Playername' equals to (your user name). Now try to register the same name two or more times, i dont think so there would be two rows with the same name. Use limit 1 if, for example, you are selecting the ammount of posts, probably 100 guys with the same post count decide to call that query at the same time, usually happens ; ) or it doesnt?. |
Well, that could be yes. However, you can only have 1 same playername in the database... so I don't think it'll change anything to the result.
|
Sweet! I was just thinking about this the other day (And TheKiller removing his tutorial about it
![]() PS: Did you find that picture on ******? I actually had a signature once which had exactly the same background image, lol. |
Not a bad tutorial on creating dynamic signatures, quite a few people would find it helpful. .
|
If I were to suggest something, it would be to add more explanation about the HTML and explain the basics of PHP so that the reader understands what they are doing rather then copying and pasting.
|
PLEASE learn when to use "string" and 'string' - that PHP code makes me cringe!
|
Maybe you can create a already done script, how many times i try, it gives mes error :/
|
If i use this i must have MySql system saving accounts or i can have .ini?
|
I am totally not experienced with this stuff on PHP, but how do you find the correct coordinates to place the information at, on the image?
|