[Tutorial] Creating dynamic signatures using PHP and MySQL.
#1

Hello everybody,

According to my thread: Dynamic Signatures?, I'm here with the tutorial.

What can I use this for?
You can use dynamic signatures to first of all, show your statistics from in-game to everybody else. It can also be used to advertise your server.

What do I need?
  • You need a webhosting which has PHP installed. You can't use homehost, except if you have installed some php server. I won't go any deeper into that because there are enough tutorials about that.
  • I recommend using Notepad ++ to script in.
  • A signature image that you'll use to put the player information in.
  • MySQL Database.
  • I also recommend to use a little php script to get your X/Y coordinates of your picture. You can do without it, but it will take some more time. Click here for more information about X/Y coorindates http://www.emanueleferonato.com/2006...th-javascript/
  • A custom font. --> www.dafont.com <---


(Optional) Part 1: Making "playername input page".
This part is optional as you can do it perfect without it. You can save this page as index.html
Please not that this script doesn't use any design.

This page will ask for a playername and send it to the php page to make an image with the player's stats..

Код HTML:
<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>
This very simple html page will look like this:




(Optional) Part 2: Getting playername information from the html page.
We will now work in signature.php. If you're using another name, you need to change the signature.php to the file you called this one. See previous code. ^^
PHP код:
$player_name=$_GET['player_name']; // This gets the player his name from the previous page. 

Part 3: Connecting to MySQL database.
You need your mysql details for this part such as username, password, database and host.
This should be in the same file as part 2.
PHP код:
/* 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."); 
Part 4: Protect Mysql injection.
This should be in the same file as part 2.
PHP код:
/* To protect MySQL injection. */
$player_name stripslashes($player_name);
$player_name mysql_real_escape_string($player_name); 
Part 5: Getting player information from the database.
This should be in the same file as part 2.

PHP код:
$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. 
We now have all the information about the player. However, we don't do anything with the player veriables.



Part 6: Making png image with the player's variables.
This should be in the same file as part 2.
I use the $text_XXXX variable as I personally think this is easier to work with.

PHP код:
// 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($im197,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($im1602036$text_color$font$text_username); // Prints the username in the picture. 
    
imagettftext($im1607269$text_color$font$text_score); // Prints the score in the picture.
    
imagettftext($im1607299$text_color$font$text_money); // Prints the money in the picture.
    
imagepng($im);
    
imagedestroy($im); 
This should be at the end of the script. We use this to close the mysql connection, else your server will be overloaded in some time.

PHP код:
mysql_close(); 
Part 7:Combining everything.

PHP код:
<? 
/*
***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($im197,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($im1602036$text_color$font$text_username); // Prints the username in the picture. 
    
imagettftext($im1607269$text_color$font$text_score); // Prints the score in the picture.
    
imagettftext($im1607299$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();
?>

Part 8: The final result:



Please comment and rate.
If you're encountering any problem, just send me a PM and I'll help you out.
If you see any mistakes in the script, just let me know below.
I hope you like this tutorial as it took me more than an hour to make.


Regards,
Nodroz
Reply


Messages In This Thread
Creating dynamic signatures using PHP and MySQL. - by Nodroz - 04.12.2011, 10:53
Re: Creating dynamic signatures using PHP and MySQL. - by Ash. - 04.12.2011, 10:54
Re: Creating dynamic signatures using PHP and MySQL. - by xantowskii - 04.12.2011, 15:27
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 04.12.2011, 15:42
Re: Creating dynamic signatures using PHP and MySQL. - by Unknown123 - 04.12.2011, 21:27
Respuesta: Re: Creating dynamic signatures using PHP and MySQL. - by kirk - 04.12.2011, 22:08
Re: Respuesta: Re: Creating dynamic signatures using PHP and MySQL. - by xantowskii - 05.12.2011, 06:02
Re: Creating dynamic signatures using PHP and MySQL. - by Hiddos - 05.12.2011, 06:40
Re: Creating dynamic signatures using PHP and MySQL. - by [HiC]TheKiller - 05.12.2011, 06:49
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 05.12.2011, 15:17
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 05.12.2011, 15:39
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 05.12.2011, 16:00
Re: Creating dynamic signatures using PHP and MySQL. - by Speed - 05.12.2011, 16:03
Re: Creating dynamic signatures using PHP and MySQL. - by System64 - 06.12.2011, 11:14
Re: Creating dynamic signatures using PHP and MySQL. - by Biesmen - 06.12.2011, 12:52
Re: Creating dynamic signatures using PHP and MySQL. - by Speed - 06.12.2011, 12:52
Re: Creating dynamic signatures using PHP and MySQL. - by No Fear - 06.12.2011, 12:54
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 06.12.2011, 15:08
Re: Creating dynamic signatures using PHP and MySQL. - by Unknown123 - 06.12.2011, 16:31
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 06.12.2011, 17:05
Re: Creating dynamic signatures using PHP and MySQL. - by Unknown123 - 06.12.2011, 17:50
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 06.12.2011, 19:02
Re: Creating dynamic signatures using PHP and MySQL. - by Unknown123 - 06.12.2011, 21:52
Re: Creating dynamic signatures using PHP and MySQL. - by Djankaa - 06.12.2011, 21:53
Re: Creating dynamic signatures using PHP and MySQL. - by Biesmen - 07.12.2011, 08:22
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 07.12.2011, 11:37
Re: Creating dynamic signatures using PHP and MySQL. - by #marcus. - 07.12.2011, 13:42
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 09.12.2011, 17:55
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 10.12.2011, 09:15
Re: Creating dynamic signatures using PHP and MySQL. - by Zonoya - 10.12.2011, 09:22
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 10.12.2011, 09:23
Re: Creating dynamic signatures using PHP and MySQL. - by Hiddos - 10.12.2011, 09:32
Re: Creating dynamic signatures using PHP and MySQL. - by Zonoya - 10.12.2011, 10:57
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 10.12.2011, 16:49
Re: Creating dynamic signatures using PHP and MySQL. - by Zonoya - 10.12.2011, 18:25
Re: Creating dynamic signatures using PHP and MySQL. - by Zonoya - 11.12.2011, 07:56
Re: Creating dynamic signatures using PHP and MySQL. - by XFlawless - 11.12.2011, 08:17
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 11.12.2011, 08:31
Re: Creating dynamic signatures using PHP and MySQL. - by gamer931215 - 12.12.2011, 09:57
Re: Creating dynamic signatures using PHP and MySQL. - by TheArcher - 12.12.2011, 15:26
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 12.12.2011, 16:10
Re: Creating dynamic signatures using PHP and MySQL. - by royal_king - 17.12.2011, 11:04
Re: Creating dynamic signatures using PHP and MySQL. - by Niko_boy - 19.12.2011, 15:46
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 19.12.2011, 15:48
Re: Creating dynamic signatures using PHP and MySQL. - by Niko_boy - 19.12.2011, 16:03
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 19.12.2011, 16:06
Re: Creating dynamic signatures using PHP and MySQL. - by TheArcher - 19.12.2011, 16:07
Re: Creating dynamic signatures using PHP and MySQL. - by Niko_boy - 19.12.2011, 16:12
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 19.12.2011, 18:09
Re: Creating dynamic signatures using PHP and MySQL. - by Niko_boy - 20.12.2011, 09:04
Re: Creating dynamic signatures using PHP and MySQL. - by GangsTa_ - 20.12.2011, 11:40
Re: Creating dynamic signatures using PHP and MySQL. - by §с†¶e®РµРe - 20.12.2011, 14:05
Re: Creating dynamic signatures using PHP and MySQL. - by System64 - 20.12.2011, 18:12
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 20.12.2011, 18:52
Re: Creating dynamic signatures using PHP and MySQL. - by System64 - 20.12.2011, 19:07
Re: Creating dynamic signatures using PHP and MySQL. - by Niko_boy - 21.12.2011, 08:31
Re: Creating dynamic signatures using PHP and MySQL. - by Nodroz - 21.12.2011, 09:32
Re: Creating dynamic signatures using PHP and MySQL. - by Britas - 21.12.2011, 16:39
Re: Creating dynamic signatures using PHP and MySQL. - by Riddy - 31.12.2011, 16:19
Re: Creating dynamic signatures using PHP and MySQL. - by aleck - 15.09.2012, 11:58
Re: Creating dynamic signatures using PHP and MySQL. - by aleck - 20.09.2012, 04:14
Re: Creating dynamic signatures using PHP and MySQL. - by Jesakos - 01.01.2013, 23:24
Re: Creating dynamic signatures using PHP and MySQL. - by Isolated - 08.04.2013, 15:12
Re: Creating dynamic signatures using PHP and MySQL. - by Isolated - 08.04.2013, 15:57
Re: Creating dynamic signatures using PHP and MySQL. - by FunnyBear - 09.04.2013, 11:08
Re: Creating dynamic signatures using PHP and MySQL. - by ReneG - 10.04.2013, 01:57
Re: Creating dynamic signatures using PHP and MySQL. - by FunnyBear - 10.04.2013, 08:54
Re: Creating dynamic signatures using PHP and MySQL. - by FunnyBear - 10.04.2013, 08:59
Re: Creating dynamic signatures using PHP and MySQL. - by Ash. - 10.04.2013, 09:13
Re: Creating dynamic signatures using PHP and MySQL. - by Ash. - 10.04.2013, 13:31
Re: Creating dynamic signatures using PHP and MySQL. - by DRUNKY - 10.06.2013, 18:22
Re: Creating dynamic signatures using PHP and MySQL. - by AiRaLoKa - 25.12.2013, 05:58
Re: Creating dynamic signatures using PHP and MySQL. - by Vasco2305 - 12.01.2014, 14:14
Re: Creating dynamic signatures using PHP and MySQL. - by TheBosss - 15.01.2014, 15:05
Re: Creating dynamic signatures using PHP and MySQL. - by TheFlyer - 16.03.2014, 16:23
Re: Creating dynamic signatures using PHP and MySQL. - by Niko_boy - 16.03.2014, 19:23
Re: Creating dynamic signatures using PHP and MySQL. - by mrsh - 18.03.2014, 14:10
Re: Creating dynamic signatures using PHP and MySQL. - by TheFlyer - 24.03.2014, 19:02
Re: Creating dynamic signatures using PHP and MySQL. - by khalildz - 18.07.2014, 18:31
Re: Creating dynamic signatures using PHP and MySQL. - by AroseKhanNiazi - 07.01.2015, 12:44

Forum Jump:


Users browsing this thread: 1 Guest(s)