Ipad detection with PHP and htaccess
Posted on Thursday 19 August 2010
This wil return a 1 value if it’s an iPad:
$ipad_or_not = (bool) strpos($_SERVER[‘HTTP_USER_AGENT’],‘iPad’);
You also can redirect with htaccess:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301]
Remove the index.php from your codeigniter URL
Posted on Sunday 19 July 2009

When you create a standard new codeigniter application, there’s always a index.php in your url. It’s kind of ugly in your url so I prefer to remove this. To remove this you need to do a couple of things:
change the $config[‘index_page’] to $config[‘index_page’]=”“ instead of $config[‘index_page’]=“index.php”
Next create a .htaccess file in the root of your CI application with the following:
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond % !-f
RewriteCond % !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Automatic config Base_url in CodeIgniter
Posted on Friday 17 July 2009

If you don‘t like to change the base_url in your Codeigniter config file every time you move your application. Just replace it with the following:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
It also works with https.
How to resize youtube or vimeo movies with PHP
Posted on Wednesday 27 May 2009

You have to use the preg_replace php function here. The $video variable holds the embed code fromyoutube, vimeo or other similar website that use these parameters in their embed codes in the example. You can change the width and height in the second parameter. This will replace the width and height parameters in you embed code with you desired width. That way inserted video‘s by users won‘t mess up your layout.
$video = preg_replace('/(width)=("[^"]*")/i', 'width="270"', $video);
$video = preg_replace('/(height)=("[^"]*")/i', 'height="270"', $video);
Multi-language support with Smarty
Posted on Wednesday 13 May 2009
Languages have always been a stumbling block for developers. With smarty you can make language files containing all the words that need to be translated and smarty will replace the language variables with the correct language. Smarty is also able to automatically check the browser language. I found this language class on the http://smarty.incutio.com/ website.
Getting started with Smarty templating
Posted on Thursday 7 May 2009

A few days ago I started using smarty. I was amazed by what you can do with this templating engine. Smarty is a templating engine written in php which allows you to easily split the PHP code from your html code. The smarty developers call it a "Template/Presentation Framework” because it‘s not just a tag replacing template engine. Templating is especially useful when you work with web designers who have little or no knowledge of PHP. They can easily change the html code in the tpl files without being bombarded with PHP code. I am a web developer and I started using a templating class which just enabled me to assign variables and blocks. I now use smarty for my CMS. It took me about 2,5 days to implement it because the templating class I used, worked completely different from Smarty. Smarty enables me to loop through arrays, use modifiers (which are basically custom PHP functions that work within smarty), cache files, debugging and so much more.
Add tweets and get latest tweets from Twitter using Twitter API
Posted on Monday 27 April 2009
This weekend I made a twitter module for our CMS. This was fairly easy to do. I included the files. You can download them below. I think the curl module has to be installed on your webserver to use it. You can get your latest posted tweet with the variable $last_tweet. To echo all of your latest tweets use the variable $twitter_tweets. It also includes a javascript file to limit the amount of characters. Twitter only allows tweets of 140 characters. Don‘t forget to change your twitter credentials on top of the index.php file. Change the $twitter_username to your username and the $twitter_psw to your password.
PHP XML sitemap generator
Posted on Monday 20 April 2009

Recently I came across a php script that automatically generates an XML sitemap.The script crawls through a website, searching for href‘s within the same domain. I‘ve altered the script a bit so it lets google know when a new xml sitemap has been generated. When your website changes a lot you should frequently update your sitemap. By using this sitemap generator you can do this without any hassle.
You can change the location of the sitemap within the index.php. Just alter the variable $filename to your location (line 451 or so). You should also change the paramater $url_xml in the pingGoogle function on line 494 to the full path of the sitemap (e.g. http://www.domain.com/sitemap.xml). Otherwise you‘ll get a 400 error on pinging google. Make sure sitemap.xml has write permissions, so chmod sitemap.xml to 777.
Backup all your databases on your server at once using php
Posted on Monday 16 February 2009

I‘ve altered a php script which I found on the php classes website, to backup all your databases at the touch of a button. The databases have to reside on the same server though. I‘ll change this when I find some spare time. You can download these files below. It includes a folder with a number of files. To use this method of database backup, you first of all have to make a database which contains all your database information like:
- db login (e.g. root)
- db password(e.g. root)
- db host(e.g. localhost)
- db database(e.g. mydatabase)
Image resizing on the fly using PHP
Posted on Friday 6 February 2009

Smart Image Resizer 1.4.1
this is one of the best PHP scripts I‘ve found so far on the internet. It‘s made under the Creative Commons license. All he asks is to include a link on your website to his website when you use his script http://shiftingpixel.com. It allows you to crop or scale an image on the fly only by setting a certain width, height and if necessary a cropratio. If you, for example, change the layout of your website and the images need to be larger, you don‘t need to scale the images all over again. Just change the parameters and the images will be cropped to that size. The original images aren‘t modified in the process. I‘ve incorporated this script in the CMS from webFizz and saved me a lot of time so far.
filter_var() input validation by PHP
Posted on Friday 6 February 2009
I recently discovered a very useful function in PHP. It‘s called filter_var(). It takes three arguments: a variable and the filter and a last optional argument, the options. The last argument uses an associative array of flags/options or a single flag/option.
filter_var(variable, filter, options);
I use it in addition to javascript validation. That way when javascript is disabled your web-application is still secure and no unwanted data enters your precious database. I mainly use the filters :
FILTER_SANITIZE_NUMBER_INT
FILTER_SANITIZE_STRING
FILTER_SANITIZE_EMAIL
FILTER_VALIDATE_EMAIL
FILTER_VALIDATE_INT.
filter_var() input validation by PHP
Posted on Friday 6 February 2009
I recently discovered a very useful function in PHP. It‘s called filter_var(). It takes three arguments: a variable and the filter and a last optional argument, the options. The last argument uses an associative array of flags/options or a single flag/option.
filter_var(variable, filter, options);
I use it in addition to javascript validation. That way when javascript is disabled your web-application is still secure and no unwanted data enters your precious database. I mainly use the filters :
FILTER_SANITIZE_NUMBER_INT
FILTER_SANITIZE_STRING
FILTER_SANITIZE_EMAIL
FILTER_VALIDATE_EMAIL
FILTER_VALIDATE_INT.