July 20 2013

Protect PHP class file that must be include

Tagged Under : ,

Here we describe how we can protect our class file that calling with include function, but it was not secure and its have big risk. For the solution if we can make the file cannot execute or calling when it not include by PHP file.

Why we need it? because when someone try calling http://localhost/module/foo.class.php it will be successful and maybe some accident will happen here.

if( basename( __FILE__ ) == basename( $_SERVER['PHP_SELF'] ) ) exit();

June 21 2013

PHP shorthand If / Else

Tagged Under :

PHP shorthand is something that even if you don’t use it yourself, you’re sure to come across it elsewhere.
For Example:
if ($age > 12) {
   $result = 'Young';
} else {
   $result = 'Adult';
You can write it as:
$result = $age > 12 ? 'Young' : 'Adult';

And I also give some example at below:

March 10 2013

PHP is_serialized function

Tagged Under :

PHP unserialize function is use to convert an array string to an array.

But if the string not in proper array string it will return Notice error like below:
Notice: unserialize() [function.unserialize]: Error at offset 0 of 6 bytes

The easy way to fix this problem is write a function and call it “is_serialized”, use to check the string before unserialize it.

March 02 2013

PHP warning: getdate() [function.getdate]: It is not safe to rely on the system’s timezone settings

Tagged Under :

I face a weird problem in PHP. I just upgrade to php 5.3.0 and since the upgrade I’m getting the following warning:
Warning: getdate() [function.getdate]: 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 the timezone identifier.
And date.timezone also added. But the warning still there.

February 03 2013

PHP use curl post xml

Tagged Under :

Because I want integrate my web application with one of the famous payment gateway. But they didn’t provide any API and just give the documentation only.

So I write the code myself to communicate the payment gateway server.

January 09 2013

Using .htaccess Protect Your Site

Tagged Under : , ,

Except from apache you can let your .htaccess file tighten up your site’s security and give extra level of protection.

I am going listing out few example and show you how to use it or where to use it. You don’t have to use every single one, just whatever you feel would help you improve your site security.