Finding Exact Document Root in PHP

You might know the DOCUMENT_ROOT value of the $_SERVER array. This value indicates the absolute location of the site directory where pages are served. In short, it’s the public folder of site as defined in the server’s configuration. Here’s a quick example : If you have a site in /home/me/site and can access it by http://site.dev, then the $_SERVER[‘DOCUMENT_ROOT’] is “/home/me/site”. If any page in the server, even if it…

How To Set Same Cookie On Different Domains

You might have seen sites like Google setting the login status cookie on the various domains of theirs (YouTube, Blogger). As you may know, cookie can’t be set in a different domain from another domain directly. If you’re having multiple sites in where you need to set a cookie from a parent site, you can use basic HTML and JS to set the cookies. Google is using this same way.…

Call Parent Class construct Before Child’s In PHP

If in PHP, you are making a child class of a parent class in which both have the __construct function and you want to call both of them when the child object is made, it won’t work. This is because, when you make the child class object, it’s construct function is called. The parent’s construct function is being overridden by the child. The PHP manual on OOP (Object Oriented Programming)…

Add Spell Check With PHP Using Google

If you google something that has spelling mistakes, Google will automatically correct it for you or if the bot isn’t sure, it will give the Did You Mean ? clause. If you’re developing a search engine for your site, this spell check will come in handy. If the user had made a mistake and he was shown a “No Results Found” page, user will be annoyed. So, it’s better to…

Fix WordPress Database Error “MySQL server has gone away..”

If you run a WordPress blog and see the error “MySQL server has gone away for query…..” on your error logs a lot, you are certainly in trouble. When this happens, your blog will be down. It happened to this blog and I started searching for a solution. Finally I got a solution and it works. It’s a simple solution. All you have to do is add 2 lines after…

How To Use Hard Disk As RAM In Ubuntu Linux

I heard that it is possible to use a portion of hard disk as RAM in Windows. I wondered if this trick is available for Ubuntu, so I googled about it and couldn’t find anything related to it. But I found out an AskUbuntu answer of using USB sticks as RAM. I did the same trick on Hard Disk and it works !! This trick can be accomplished with the…