If you are using PDO (PHP Data Objects) and you’re having problems with utf-8, try to add PDO::MYSQL_ATTR_INIT_COMMAND option inside PDO definition like I wrote below. $db = new PDO( …
Category: PHP
Detect mobile browser (smartphone)
Detecting mobile browsers is very easy when you know the right regular expression. Here are two examples (for PHP and JSP) PHP <?php $useragent = $_SERVER[’HTTP_USER_AGENT’]; if (preg_match(’/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( …
Detect visitor IP address with PHP
Two post in 2 days… 🙂 Here is a small PHP function to detect remote IP address (visitor IP address). This should work even if the client/visitor is behind a …
Upgrading PHP and MySQL on CentOS or RHEL
I already wrote about upgrading via Jason Litka repo on this PAGE but in case you have problems with this repo, you can add Remi Collet repo. First, import Remi …
PHP redirect
It is not hard to remember but here it is… This code can be used to redirect visitors to any other page. header("Location: http://www.blabla.com/page.php");header("Location: http://www.blabla.com/page.php");
PHP error reporting
Error reporting in PHP is a very usable option but sometimes you can be buried with “PHP Notice” lines which you don’t need (save space and bandwith). PHP Notice: Undefined …
Using PHP as a shell scripting language
As most of us already know, PHP is one of the most popular scripting language for developing dynamic web pages. But you probably don’t know that PHP can be used …
Upgrading to PHP 5.2.5 on RHEL and CentOS
As you probably know, the latest CentOS and RHEL distros are available only with PHP 5.1.6 and if you want to upgrade PHP, you need to install it manually (or …