Archive for the ‘PHP’ Category.
March 15, 2010, 10:46 am
I was playing with Drupal 6 and some UberCart ticket module when I came across an error message where Drupal told me that it needed the IMAP PHP extension to be installed. Because I’m a nice guy I will share this command with you: [me@it ~]# yum install php-imap Now it’s installed, proof: [me@it ~]# [...]
March 8, 2010, 6:29 pm
Here is a function for getting the URL of the page being processed in PHP, the function accepts one optional parameter $ignore_port_80 (boolean) to tell it whether it should ignore the port part of the url if the port used is 80: # Function function get_current_url($ignore_port_80 = true) { $is_https = $_SERVER['HTTPS'] === ‘on’; $show_port [...]
January 27, 2010, 11:05 am
A lot of web hosts have limited or nonexistent support for PEAR, the pear command will throw errors on most commands or not work at all, in order to install Symfony on such hosts you will need to download the Symfony package, copy Symfony files to your home directory and make them easily accessible from [...]
August 7, 2009, 11:00 am
The Problem Do you know a method in PHP to check the type of an uploaded file without relying on extension or Mime-type because these two can be faked? Verifying the file type in PHP Relying on the Mime-type of a file submitted by a user is a bad practice, using the extension is even [...]
August 5, 2009, 6:35 am
This also was about to drive me crazy so I will not let it go without writing about it.. Let’s say you have some long HTML code contained on a PHP variable, something like this <?php # define the $html variable using the # Nowdoc syntax to avoid parsing $html = <<<’HTML’ <div id=”box”> <h1>Title</h1> [...]
August 4, 2009, 4:43 am
There are many ways to retrieve files extension with PHP, but we will have to choose one that feets our needs and gives more reliable results. When dealing with file extension you should know that a file extension is not always 3 characters long (ex: foto.jpeg, index.html) and that it doesn’t start after the last [...]
June 24, 2009, 10:27 am
Oddly enough, PHP 5.2.6 is still not available on default CentOS repositories ([base], [updates], [addons], and [extras]), latest PHP available in those repos is PHP 5.1.6! In order to install PHP 5.2.6 you can add the CentOS testing repository and enable it then install or update PHP. To add the CentOS testing directory, create a [...]
June 23, 2009, 5:50 pm
Warning: preg_match() [function.preg-match]: Compilation failed: repeated subpattern is too long at offset 18454 in /var/www/html/[...]/Smarty/Smarty_Compiler.class.php on line 454 It looks that you are running an old version of Smarty, latest version as I write is 2.6.26, you can download it from here.
January 13, 2009, 6:37 pm
In mathematics, one of the definitions of odd and even number is that they can be expressed like this (where n is the number and k is an integer): Odd numbers: n = 2k +1 Even numbers: n = 2k In PHP, we can check a number’s parity by checking the remainider of the division [...]