Original thread:
http://villavu.com/forum/showthread.php?t=83538
Recently a few members of Villavu have been trying to re-create signature which update to their server. Some have been having issues.
Myself, Kyle and [J]ustin have done this to test it and found a few twists and turns in the tutorials which can throw people off, so this is hopefully a full fix for that tutorial.
What will you learn?
You will be learning a little PHP (Enough to progress you into further projects I think). Pascal and some logical thinking
What will I need?
- A Webhost with MYSQL Databasing
- An Image
Ok, so first things first we need to create a website, Putonajonny suggested:
Steps from here:
- Sign up using the registration, You don't want to pay so use a subdomain
- Confirm your email
- Go to the control panel of your selected sub domain, scroll or press CTRL + F to find Software / Services and click on the MYSQL icon (Should be a dolphin or something)
- Create a new database and a user, SAVE THESE DETAILS. YOU WILL NEED THEM.
- Now that you have a database and user, you need to manage it. So click on PHPMyAdmin and enter your database
So from this point we are inside the Database, this can get a little confusing so we will take baby steps!
The best way I can explain these databases is to imagine them like Excel spread sheets. The database is the document, the tables are the worksheets and all the parts inside is the data!
Firstly we will need to create a new database. If you are using 000webhost you will have a different PHPMyAdmin to most main hosts but have no fear! It's pretty much the same.
So following Putona's tutorial we will name the Table to be "Table1". (Case sensitive).
From here we need to create fields! So for now add 3-4 depending on how many variables you are using.
Here is an example of how the table details should look (I used Excel to explain it).
Putona used this explanation which is fairly good describing all of the options:
Your fields should now look like this:
So far so good? I hope so!
With my technique it doesn't matter what you use My Scripts name as, it's only for personal use so you can read it easier.
Eventually with more scripts it will do this:
What ID auto increment means is that each time you submit a new script name it will automatically add a new ID
Connecting our database up.
Ok, so now we need to create a PHP file!
To do this, create a new file (Preferably a text file) and name it
Commit.php (or anything you want.php) but make sure to save it as a PHP file and not a text file
Inside here you want to put your Database information!
PHP Code:
<?PHP
$user_name = "usename"; //Username for the account you created earlier
$pass_word = "password"; //Password for the account you created earlier
$database = "database"; //The name of the database you created earlier
$server = "MySQLServer"; //With 000webhost this can be found by going to your control panel then clicking MySQL
We also need to actually connect the database...
PHP Code:
$db_handle = mysql_connect($server, $user_name, $pass_word); or die(mysql_error());
$db_found = mysql_select_db($database, $db_handle); or die(mysql_error());
What this does is check the database is connecting and if not it will tell you the error
Now we are going to check if the database is found and if it is then do the following!
PHP Code:
if ($db_found) {
$SQL = "SELECT * FROM `Table1` WHERE `ID` = 1";
$result = mysql_query($SQL);
if($result){
while ($db_field = mysql_fetch_assoc($result)){
$time = $db_field['Time'];
$tokens = $db_field['XP'];
}
Now there are two parts in this, the table and ID + the Variables.
$SQL = "SELECT * FROM `Table1` WHERE `ID` =1"; basically checks in Table1 and finds all of the information inside the row of ID1.
PHP Code:
$time = $db_field['Time'];
$tokens = $db_field['XP'];
Another image which will hopefully explain it!
PHP Code:
header("Content-type: image/png");
putenv("GDFONTPATH=".realpath("."));
$img = imagecreatefrompng("signature.png");
$color["yellow"] = imagecolorallocate( $img, 255, 255, 0 );
$color["white"] = imagecolorallocate( $img, 255, 255, 255 );
$color["green"] = imagecolorallocate( $img, 0, 255, 0 );
$color["orange"] = imagecolorallocate( $img, 254, 179, 0 );
$color["purple"] = imagecolorallocate( $img, 128, 0, 128 );
$color["dblue"] = imagecolorallocate( $img, 37, 84, 199 );
if you want to make it something other than a PNG, read this:
http://php.net/manual/en/function.header.php
$img = is the location of the background on your root.
putenv("GDFONTPATH=".realpath("."));
basically means the font should be in the root of the site
This section is a little more creative!
Now to change the text on the signature!
PHP Code:
//size x y
imagettftextshadow($img, 20, 0, 25, 30, $color["dblue"], "font.ttf", "Script name");
imagettftextshadow($img, 12, 0, 10, 56, $color["orange"], "font.ttf", "XP Gained: ");
imagettftextshadow($img, 12, 0, 90, 56, $color["purple"], "font.ttf", number_format($XP));
imagettftextshadow($img, 12, 0, 10, 76, $color["orange"], "font.ttf", "Total Time: ");
imagettftextshadow($img, 12, 0, 120, 76, $color["purple"], "font.ttf", formatMilliseconds($time * 1000));
imagepng($img);
imagedestroy($img);
}
This is pretty much it, you have defined your color, the text and what its printing..
E.g the $ stuff
SIMBA part:
Add this in the mainloop:
AddOnTerminate('SendData');//To make it send the data
Simba Code:
Function SendData : Boolean;
Var
i : integer;
begin
i := InitializeHTTPClientWrap(False); //this creates a client
AddPostVariable(i, 'time', IntToStr(GetTimeRunning / 1000));//This adds our info to the client
AddPostVariable(i, 'runs', IntToStr(XPGained));
Result := Pos('true', Lowercase(PostHTTPPageEx(i, 'http://mywebsite.net/MyPage.php'))) <> 0;//Then this posts it
FreeHTTPClient(i);//Remember to free it
end;
Full PHP bit:
PHP Code:
<?PHP //Milliseconds Function
function formatMilliseconds($milliseconds) {
$seconds = floor($milliseconds / 1000);
$minutes = floor($seconds / 60);
$hours = floor($minutes / 60);
$days = floor($hours / 24);
$milliseconds = $milliseconds % 1000;
$seconds = $seconds % 60;
$minutes = $minutes % 60;
$hours = $hours % 24;
if($days == 0){
$format = '%uhours, %02uminutes and %02u seconds';
$time = sprintf($format, $hours, $minutes, $seconds);
return rtrim($time, '0');
}else{
$format = 'Úys, %uhours, %02uminutes';
$time = sprintf($format, $days, $hours, $minutes, $seconds);
return rtrim($time, '0');
}
}
//imagettftext function
function imagettftextshadow($image, $size, $angle, $x, $y, $color, $fontfile, $text) {
imagettftext($image, $size, $angle, $x + 1, $y + 1, imagecolorallocate($image, 0, 0, 0), $fontfile, $text);
imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text);
}
//Database
$user_name = "DBUsername"; //Username for the account you created earlier
$pass_word = "Password"; //Password for the account you created earlier
$database = "DBname"; //The name of the database you created earlier
$server = "localhost"; //With 000webhost this can be found by going to your control panel then clicking MySQL
$db_handle = mysql_connect($server, $user_name, $pass_word) or die(mysql_error());
$db_found = mysql_select_db($database, $db_handle) or die(mysql_error());
//Script
if ($db_found) {
$SQL = "SELECT * FROM `table1` WHERE `ID` = 1";
$result = mysql_query($SQL);
if($result){
while ($db_field = mysql_fetch_assoc($result)){
$time = $db_field['Time'];
$xp = $db_field['XP'];
}
header("Content-type: image/png");
putenv("GDFONTPATH=".realpath("."));
$img = imagecreatefrompng("sig.png");
$color["yellow"] = imagecolorallocate( $img, 255, 255, 0 );
$color["white"] = imagecolorallocate( $img, 255, 255, 255 );
$color["green"] = imagecolorallocate( $img, 0, 255, 0 );
$color["orange"] = imagecolorallocate( $img, 254, 179, 0 );
$color["purple"] = imagecolorallocate( $img, 128, 0, 128 );
$color["dblue"] = imagecolorallocate( $img, 37, 84, 199 );
imagettftextshadow($img, 12, 0, 10, 50, $color["orange"], "sans.ttf", "XP Gained: ");
imagettftextshadow($img, 12, 0, 90, 50, $color["purple"], "sans.ttf", number_format($xp));
imagettftextshadow($img, 12, 0, 10, 70, $color["white"], "sans.ttf", "Time Run: ");
imagettftextshadow($img, 12, 0, 90, 70, $color["purple"], "sans.ttf", formatMilliseconds($time * 1000));
imagepng($img);
imagedestroy($img);
}else
print "Not working";
}
else
print "DB not Found, please report this";
?>
SQL Injection:
[J]ustin reminded me of this ^^
SQL Injection can be a pain in the arse, they can find your details, put stuff onto your website etc. So you need protection!
This is the function:
PHP Code:
mysql_real_escape_string();
This is it in use:
PHP Code:
mysql_real_escape_string($SQL);
Tutorial:
http://www.tizag.com/mysqlTutorial/m...-injection.php