How to Convert an Array to an Object?

PHP arrays are cool, but if you are switching to the modern coding standards (OOP) you are probably in need of objects more often. PHP provides a very easy way to change the type of a variable from an...

Get the Current URL of Page with PHP

This simple snippet of code will help you get the full URL of the currently viewed page. function getUrl(){ $domain = $_SERVER['HTTP_HOST']; $url = "http://" . $domain . $_SERVER['REQUEST_URI']; retur...

How to Grab Youtube Video Thumbnail?

Getting the thumbnail of a Youtube video through it’s ID is not that hard. You just have to transform the URL a little bit to get a high quality JPG file, used as a main thumbnail through Youtub...

Stop WordPress Comment Spam

Yes, Akismet can be of huge help when fighting with comment spam, but it can’t help against the most sophisticated auto-commenting tools which make fake comments look very real....

How to Fix a “unexpected $end” Error

Sometimes you will get an error similar to this in PHP: Parse error: syntax error, unexpected $end in /index.php on line 36 This is most likely caused by a forgotten closing curly bracket (“}...

How to Set a Cookie to Never Expire

Sometimes, while working with Cookies in PHP you may want to make a cookie never expire (e.g. in a rating script where you set a cookie on user’s computers, although it’s not wise to use c...

PHP Login Script Example

This PHP login script example is a very simple login system which you can use as a base for your future projects. You should note that it needs to be secured before using on a live system. Some things...

Simple PHP HTTP Authentication

Sometimes you may want to hide the contents of a page (e.g. admin page) in a very simple manner. The best and simplest method is to use the PHP’s built in HTTP authentication. It’s both se...

“I Can’t Access a Cookie I Set In PHP”

A lot of people (including me) experience problem accessing a cookie immediately after setting it. The thing is that you can’t access a cookie inside the same request that is used to set it....

Optimize PHP Script – Best Tips

Using PHP is great for dynamic website. However, more dynamic means more resource hungry. Here is a short list of tips you should follow to avoid putting the PHP interpreter in difficulty....