Short Tag – Web Development Blog

Entries for the ‘PHP’ Category


Php doesn’t have direct functions for AES encryption and decryption like MySql.
These functions will do exactly what the MySql functions do.
Encypt function:

function AES_ENCRYPT($value, $secret)
return rtrim(

How to disable XDebug

If you want to disable XDebug on your server for some reason, you can do one of the following:
1.) Locate your php.ini file (the server’s php.ini or if your server allows it create one in the root of your website). Find the following directives and change them as below:


2.) Disable it just for one website [...]

PHP Reflection Class – The basics

Part1 – Using the ReflectionClass in PHP to get basic information about a class.
Build the Refelection Class

$class = new ReflectionClass($className);

$className – can be the name of any class
Get the name of the class:

echo $class->getName()

Get the name of the file that contains the class:

echo $class->getFileName()

Get the class inherited by this class:

echo $class->getParentClass();

Get all the list [...]

Php .Htaccess Set default timezone

When getting an error like this:
© Warning: date(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled [...]

PHP str_replace

PHP’s str_replace function will replace every occurrence of the selected string with another string.

echo str_replace("car", "bike", "That car is red!");

The code above displays the text: That bike is red!
Function parameters:
str_replace(searched_string, replacement_string, target_string, count)
searched_string – the string that will be replaced
replacement_string – the string that will be used to replace the searched string
target_string – the string [...]

SoundCloud API – get number of followers

In order to get the number of followers of a user you have to:
1.) create a SoundCloud application:
2.) use this code in your website (and replace {$user_id} with your username, replace {$client_id} with the application’s Client id – displayed after you create the application):

$sc_content = file_get_contents("{$user_id}?consumer_key={$client_id}");
$sc_xml = simplexml_load_string($sc_content);

echo $sc_xml -> {‘followers-count’};

And that’s all!

PHP MIME E-mail decoding with PEAR’s MimeDecode

In my previous article “PHP e-mail PIPE, cPanel PIPE forwarding” I was explaining how you can create an e-mail PIPE and get the e-mail with PHP.
This is the code you should use to get the email from stdin:

// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);

Now, we have the content [...]

PHP e-mail PIPE, cPanel PIPE forwarding

E-mail PIPEs are e-mail forwarders that forward an email to an application and not an other email address. Recently I had to develop such a script so I thought I could share what I learned with you.
1.) Setting up the PIPE
Firstly you have to make sure your web hosting provider allows you to create E-mail [...]

Get the values of PHP directives

echo ini_get("post_max_size");

This is the way you get the values of a PHP directive. It is a very handy function.
It can be used to:
* check if register globals is active on server or not: ini_get(“register_globals”)
* check what is the max upload and post size at upload: ini_get(“post_max_size”), ini_get(“upload_max_filesize”)
* check what is the max execution time for [...]

Connect to multiple Mysql databases with PHP

Sometimes we need to connect to multiple databases with our PHP script. Try not to connect to too many different hosts, this can increase considerably the execution time of your script.
First, I create the 2 connection with 2 hosts:

$user1 = "";
$pass1 = "";
$db1 = "";
$host1= "";
$conn1 = mysql_connect($host1, $user1, $pass1);

$user2 = "";
$pass2 = "";
$db2 [...]