Dynamic signature – create image and set with a variable Author x0r3n
It's kind of messy, not perfect. But it's a good start.
Here is the sigtext.php file (set your signatures text)
<?php
if (isset($_POST['sText'])) {
$tLen = strlen($_POST['sText']);
if ($tLen > 19) {
echo "Please make your text shorter, 19 character is the limit.";
}
}
?>
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="phpal" />
<title>Set my sig!</title>
</head>
<body>
<form name="sig" action="signature.php" method="post">
Text: <input type="text" name="sText" />
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>
signature.php file (where the magic happens)
<?php
require_once('config.php');
/**
* @author phpal.in
* @copyright 2011
* @purpose dynamic signature
*/
$checkDB = mysql_query("SELECT * FROM sigs");
$empty = mysql_num_rows($checkDB);
if (isset($_POST['submit'])) {
$text = mysql_real_escape_string($_POST['sText']);
$text = htmlspecialchars(strtolower($_POST['sText']));
$ip = $_SERVER['REMOTE_ADDR'];
$date = date("Y-m-d H:i:s");
$storeIt = mysql_query("INSERT INTO sigs (id, text, ip, datetime) VALUES ('', '$text', '$ip', '$date')");
}
header('Content-Type: image/png');
$base = '/sig/base.png';
$font = "PIXEAB__.TTF";
$dir = $_SERVER['DOCUMENT_ROOT'] . $base;
$query = "SELECT text FROM sigs ORDER BY datetime DESC LIMIT 1";
$getLatest = mysql_query($query) or die("Error grabbing latest text.");
$newText = mysql_fetch_array($getLatest);
if (is_file($dir)) {
$images = glob($dir . "*.png");
$im = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'] . $base);
if ($im) {
$red = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, 20, 0, 15, 70, $red, $font, $newText['text']);
imagepng($im);
imagedestroy($im);
} else {
echo "Failed to create the image.";
}
} else {
$dir . " Is not a valid base file.";
}
?>
config.php file (DB connection)
<?php /** * @author phpal.in * @copyright 2011 */ $mysql['config']['hostname'] = "localhost"; $mysql['config']['database'] = "sig"; $mysql['config']['username'] = "root"; $mysql['config']['password'] = ""; $mysql['config']['connection'] = mysql_connect($mysql['config']['hostname'], $mysql['config']['username'], $mysql['config']['password']); mysql_select_db($mysql['config']['database'], $mysql['config']['connection']); ?>
Base image (save as base.png)

Font file URL:
http://examples.phpal.in/sig/PIXEAB__.TTF (save as PIXEAB__.TTF)
.htaccess (make your .php come out as .png)
RewriteEngine On RewriteRule sig.png signature.php
SQL for your database:
-- phpMyAdmin SQL Dump -- version 3.4.5 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Nov 10, 2011 at 08:35 PM -- Server version: 5.1.56 -- PHP Version: 5.2.9 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `phpalin_sig` -- -- -- -- -- Table structure for table `sigs` -- CREATE TABLE IF NOT EXISTS `sigs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `text` varchar(85) NOT NULL, `ip` varchar(55) NOT NULL, `datetime` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=26 ; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
This should be everything you need, just set up your config to match your settings. Then set your text in your DB once then make sure it worked (it should show your text). It isn't perfect (it's far from it), but it will get the job done. Feel fee to modify it in any way just please leave my credits at the top of signature.php.
[Preview] PlayPal – Have fun with your money! Author x0r3n
We are happy to release version one of PlayPal™. PlayPal is an advanced banking system/semi-game. It is coded in VB.NET, PHP, and MySQL. It has many features, and many of them are focused on keeping the game safe and secure. We focused on making sure there were no vulnerabilities or glitches. We plan to evolve this program into a fully featured game. Keep following our threads! Team: Real[visual basic dot net]
Me (this blogs owner)[Php][MySQL]
ØutƦage[Gfx]
Finished: [*]Login and registration system [*]Transactions [*]Generating money (Bankers only) [*]Userlists [*]Many security features In progress: [*]Logging system [Vb only] [*]Rankings [Vb only] [*]Recommend something! Screenshots: LoginMain
Register
Banker
Logs
JSON Author klaasy
A quick article on JSON. What is JSON? JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. (http://www.json.org/) With JSON you can "convert" an array to a string, and you can store that string in any type of file, such as .txt or .json, practically anything. Now how do we use it? Try running the following code:<?php $arr = array(1 => "Hey mike",2 => "Wazzup dawg","three" => 1337,"dog" => "cat", "Some array" => array(1 => "A ARRAY IN A ARRAY WTF?!?!?","You mad" => "Trololo")); echo json_encode($arr); ?>The output should be:
{"1":"Hey mike","2":"Wazzup dawg","three":1337,"dog":"cat","Some array":{"1":"A ARRAY IN A ARRAY WTF?!?!?","You mad":"Trololo"}}You can see that a array is opened with { (left curly brace) and closed with } (right curly brace), keys with or without values are split with a , (comma) and keys and values are "linked" with a : (colon)
Now we've got this string, let's turn it back into a array, try running this code:
<?php $json = '{"1":"Hey mike","2":"Wazzup dawg","three":1337,"dog":"cat","Some array":{"1":"A ARRAY IN A ARRAY WTF?!?!?","You mad":"Trololo"}}'; $arr = json_decode($json,true); print_r($arr); ?>The output should be:
Array ( [1] => Hey mike [2] => Wazzup dawg [three] => 1337 [dog] => cat [Some array] => Array ( [1] => A ARRAY IN A ARRAY WTF?!?!? [You mad] => Trololo ) ) Hey mikeAnd here we have our array back again
You may have noticed the second parameter at json_decode, saying true, if this isn't set to true (you can leave that parameter in that case),
it will become a stdClass Object
The output would then look like this:stdClass Object ( [1] => Hey mike [2] => Wazzup dawg [three] => 1337 [dog] => cat [Some array] => stdClass Object ( [1] => A ARRAY IN A ARRAY WTF?!?!? [You mad] => Trololo ) )That's all, hope you learned from this!
MySQLi – Prepared Statements Author klaasy
Sick of getting SQL Injected? Annoyed of the simple mysql_query function? Well use Prepared Statements!
What is a Prepared Statement?
When you are using a Prepared Statement, you "prepare" a query, you fill in all the variables with ?, the ? are called params (parameters), you can assign a new value to those params with another function, well best is to just show it.
A Prepared Statement is build up like this:
- Preparing the query
- Assigning values to the params
- Execute the query
- Bind the result
- Fetch the data (If you are using SELECT)
- Close the query
So how do we do that?
Like this:
<?php
$mysqli = new mysqli('host','user','pass','database'); //Create a connection with the database using MySQLi
$params = array(1 => 12, 2 => "tennis");
if($stmt = $mysqli->prepare("SELECT name,rank FROM users WHERE id=? AND hobby=?")){ //Prepare the query (Step 1)
$stmt->bind_param("is",$params[1],$params[2]); //Bind the params, further explanation after this code
$stmt->execute(); //Execute the query
$stmt->bind_result($name,$rank); //Bind the value of the colums we selected, notice that the variable names match the order of columns we select, variable names can be anything
$stmt->fetch(); //Fill in the data we retrieved
}
$stmt->close(); //Close the query
?>
First read the comments, now let me explain the bind_param function.
The first parameter, in this case, "is", tells the statement what kind of variables it's dealing with, because $params[1], is an integer (i) and $params[2] is a string (s), the next two parameters fill up the question marks (?'s) in the query.
Now you can do anything you want with the variables you got, in this case $name and $rank. a UPDATE, DROP and INSERT statement only requires you to prepare it, bind the parameters and execute it.
If you fetch more than one row, and you want to do something with it, do this:
while($stmt->fetch()){
echo $name." has the rank of ".$rank;
}
This is how a basic SELECT statement is done! Have fun
Working with .mp3 files in PHP Author x0r3n
I had never been interested in working with audio, but I realized I would never know when I would need to know something about it for a project. First thing is you will need the getid3() library it cna be downloaded from here: http://www.getid3.org/ Once you have it extract all the files to a directory. I used id3 for example. But any will do next createa folder inside the other called mp3. To make sure it is working on your system navigate tp: domain.ext/path/to/id3/demos/demo.browse.php If it says magic quotes is on in an htaccess file write: php_flag magic_quotes_gpc Off That should fix that. In here put any .mp3 file, now go back up to your newly created golder and make a new file called idmp3.php Then enter this code into it:
<?php
require_once('/getid3/getid3.php');
$getID3 = new getID3;
$mp3 = "mp3/daynnite.mp3";
$info = $getID3->analyze($mp3);
echo "<pre>";
print_r($info);
echo "</pre>";
?>
The first line of our code includes our library of functions for id3 usage. then we initialize the class by creating a new instance of the class. Then we give the path to our mp3 file (I used Kid Cudi's day n nite for example, any will be fine). Then with the next line we analyze our MP3 and store the information in a variable called info. The <pre></pre> just makes it easier to read. Then we print the array for the user to see. Your output should look similar to:After you are successful with this, it's time to only get the information that matters. Such as the filename, length, album name, etc. We would do this by modifying our code to be:
<?php
require_once ('/getid3/getid3.php');
$getID3 = new getID3;
$mp3 = "mp3/daynnite.mp3";
$info = $getID3->analyze($mp3);
$bytes = $info['filesize'];
echo "<pre>";
echo "Filename: ";
echo $info['filename'];
echo "<br />";
echo "Format: ";
echo $info['fileformat'];
echo "<br />";
echo "Filesize: ";
echo ByteSize($bytes);
echo "</pre>";
//functions
function ByteSize($bytes)
{
$size = $bytes / 1024;
if ($size < 1024) {
$size = number_format($size, 2);
$size .= ' KB';
} else {
if ($size / 1024 < 1024) {
$size = number_format($size / 1024, 2);
$size .= ' MB';
} else
if ($size / 1024 / 1024 < 1024) {
$size = number_format($size / 1024 / 1024, 2);
$size .= ' GB';
}
}
return $size;
}
?>
The function you see I got from: http://www.phpfront.com/php/Convert-Bytes-to-corresponding-size/ Reading megabytes is much easier than a huge integer value representing kilobytes. But as you can see I made it easy to read and only printed what I wanted to display. With the extra echoes. You should now see something similar to: Filename: daynnite.mp3 Format: mp3 Filesize: 4.27 MB That's all for this article, hope you enjoyed it. Ask any questions in the description.
Looking for skilled PHP coders who are interested in writing tutorials, and other informational posts Author x0r3n
I am looking for authors for my blog as I may not have as much time in the future.
You should be a highly skilled coder I will need to see proof of this in some way.
Not looking for people who do mainstream things, you should be skilled with sockets, cURL, etc.
**THIS IS NOT A PAYING POSITION**
I can offer traffic to your posts and a sub-domain for examples.
Please make a comment here if interested or email me at: hexen0r@gmail.com
My friend spax PHP chat box, easy to use low resources Author x0r3n
Features:
- NEW! Multiple Shoutbox Rooms
- NEW! User Chat Backgrounds
- NEW! jQuery Effects
- NEW! Support BBCodes
- NEW! Chat Commands
- NEW! Shoutmix's Chat Template
- NEW! Chat Sessions/User Online List/Ability to change Username
- User Chat Icons
- User Colors
- No need MySQL Database (txt-based)
HTML:
<iframe src="http://infinity-arts.com/ichat/?roomid=YOUR_ROOM_ID" width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>
Keep credits please!
Build 1.0.2.0 Folders needed:
- ichat/css
- /images
- ichat/inc
- /js
- /php
- /temp
- /txt
[/list]
PHP - ichat/chat.php:
main php code: http://phpal.in/phpalscripts/chat.php.txt
CSS - ichat/css/shoutbox.css:
GIF - ichat/css/images/act_indicator.gif:
PNG - ichat/css/images/Moderator-icon.png:
Javascript - ichat/inc/js/jquery-1.3.2.min.js
Javascript - ichat/inc/js/shoutbox.js
PHP Class - ichat/inc/php/class.bbcodes.php
http://phpal.in/phpalscripts/class.bbcodes.php.txt
HTML Template - ichat/inc/temp/template.newroom.html:
http://phpal.in/phpalscripts/template.newroom.php.txt
HTML Template - inc/temp/shoutmix.html:
http://phpal.in/phpalscripts/shoutmix.html.txt
Simple website status checker Author x0r3n
Ok, I haven't done anything here with cURL. It is basically a way to work with url's and get and send variables. I have made a simple website status checker. It is really simple, a lot can be done to it to make it better. But here is my basic (but commented) code.
<?php
//phpal.in simple status checker
$url = "http://www.google.com";
//open the curl connection
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true); //sets the request method to HTTP(s)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //follows and redirects
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4); //sets the timeout limit for requesting a page
curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //checks if the site is down or not
curl_close($ch);
if (200 == $httpcode) {
echo "<center><font face=\"Impact\" size=\"60\" color=\"green\">";
echo "<font color=\"black\"><a href=\"$url\">$url</a></font> is up<br />";
echo "</font></center>";
} else {
echo "<center><font face=\"Impact\" size=\"60\" color=\"red\">";
echo "<font color=\"black\">$url</font> is down<br />";
echo "</font></center>";
}
?>
You could do a lot to this code to make it work better and optimize it, this is just the barebones. If you want to learn more about
cURL you can view all of its functions here: http://php.net/manual/en/book.curl.php
Edit: Modified version to accept a user supplied URL (very minor modification):
URL to check:
<form name="url" action="status2.php" method="post">
<input type="text" name="url" />
<input type="submit" id="submit" name="submit" value="submit" />
</form>
<?php
if (isset($_POST['submit'])) {
//phpal.in simple status checker
$url = $_POST['url'];
//open the curl connection
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true); //sets the request method to HTTP(s)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //follows and redirects
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4); //sets the timeout limit for requesting a page
curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //checks if the site is down or not
curl_close($ch);
if (200 == $httpcode) {
echo "<center><font face=\"Impact\" size=\"60\" color=\"green\">";
echo "<font color=\"black\"><a href=\"$url\">$url</a></font> is up<br />";
echo "</font></center>";
} else {
echo "<center><font face=\"Impact\" size=\"60\" color=\"red\">";
echo "<font color=\"black\">$url</font> is down<br />";
echo "</font></center>";
}
}
?>
Start protecting your users passwords with salt! Author x0r3n
It's time to stop using MD5 in my opinion. There are many crackers out there for it and rainbow tables. SHA1 is much more secure and is very easy to use (like MD5). Then after you use SHA1 you should always salt it (in my opinion). For those of you who don't know, salting a hash is giving the hash something to base it off of instead of generically generating it.
If you don't believe me here are some things you can do:
create a new php file and name it anything, enter this into it:
<?php $encryptThis = "foo"; $hashit = sha1($encryptThis); echo $hashit; ?>
Then take the output of $hashit and enter it into any SHA1 cracker. I tried it on http://www.md5decrypter.co.uk/sha1-decrypt.aspx
That I found via google, Here is a screenshot of the result:

Next go into that PHP file you created earlier and append the code to match:
<?php $encryptThis = "foo"; $salt = "1337"; $hashit = sha1($salt . $encryptThis); echo $hashit; ?>
you can change the salt to anything.
Run this script and get the hash of it. Remember though the password is still the same, so it should still decrypt it with that weird salt thing?
Nope, salt completely changes the algorithm. Let's try it:

WOW, such a simple password was not found??
Yes, as I said before salt is the game changer.
Why wouldn't I use MD5 and salt?
Why would you? sha1 is an overall more secure hashing method and with salt it is extremely hard to decrypt.
Next are some examples on how to implement it:
<?php //first we need to actually generate a dyamic salt using rand() $salt = rand(3232, 9657); $password = $_POST['password']; $passenc = sha1($salt.$password); //then we would insert $passenc into the DB along with $salt. //Registration system example ?>
Logging in and getting the users salt:
<?php $sql = "SELECT * FROM table WHERE username = '$username'"; $result = mysql_query($sql) or die (mysql_error()); $row = mysql_fetch_array($result); //after the salt is grabbed from the database use it to generate the proper hash for the users password $passenc = sha1($row['salt'].$password); //login example ?>
As you can see it doesn't take much to use a salt. It will make your users passwords a heck of a lot safer.
Updated: simple copy from file then paste into file Author x0r3n
I realized I should have implemented more checks into the script to let the user know what was going on and I have done it.
The script is below and here is a result of a complete success:
<?php
/**
* @author phpal.in
* @copyright 2011
**/
$fileToOpen = 'C:\\xampp\\htdocs\\get.txt';
$newFile = "C:\\xampp\\htdocs\\paste1.txt";
if (is_readable($fileToOpen) || file_exists($fileToOpen) == true || is_writeable($newFile)) {
echo "<font color=\"green\">$fileToOpen is readable and exists, processing.</font><br />\n";
//opens it for reading
$file = fopen($fileToOpen, 'r');
//actually reads it and gets everything thanks to filesize()
$readText = fread($file, filesize($fileToOpen));
if (file_exists($newFile)) {
echo "<font color=\"red\">Script exiting, $newFile already exists.</font>";
exit(0);
} else {
//opens the new file for creation
$handle = fopen($newFile, "w+");
//writes the old text into the new one
$writenew = fwrite($handle, $readText);
//if it was successful, display a message.
if ($writenew == true) {
echo "<font color=\"green\">Data copied successfully. The data was: \"" . $readText .
"\"</font>";
} else {
echo "<font color=\"red\">Data was not copied successfully, check the script paths.</font>";
}
}
fclose($handle);
fclose($file);
} else {
echo "<font color=\"red\">$fileToOpen is unwritable.</font>";
exit(0);
}
?>
We are happy to release version one of PlayPal™. PlayPal is an advanced banking system/semi-game. It is coded in VB.NET, PHP, and MySQL. It has many features, and many of them are focused on keeping the game safe and secure. We focused on making sure there were no vulnerabilities or glitches. We plan to evolve this program into a fully featured game. Keep following our threads!
Team:
Main
Register
Banker
Logs


