Archive for the ‘ PHP ’ Category

iPhone & iPod Detection

For detecting iPhone / iPod / iPad users and redirecting them to their iPhone-compatible website you can use this simple code snippets:

PHP

1
2
3
4
5
6
7
8
9
if(
    strstr($_SERVER['HTTP_USER_AGENT'],'iPhone') ||
    strstr($_SERVER['HTTP_USER_AGENT'],'iPod') ||
    strstr($_SERVER['HTTP_USER_AGENT'],'iPad')
)
{
    header('Location: http://yoursite.com/iphone');
    exit();
}

Javascript

1
2
3
4
5
6
7
8
if(
    (navigator.userAgent.match(/iPhone/i)) ||
    (navigator.userAgent.match(/iPod/i)) ||
    (navigator.userAgent.match(/iPad/i))
)
{
    //Your redirection code here
}

.htaccess

1
2
3
4
5
6
7
8
RewriteCond %{HTTP_USER_AGENT} ^.*iPad.*$
RewriteRule ^(.*)$ http://ipad.yourdomain.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]

Wordpress. Flash uploader. HTTP error

For fix the Flash upload HTTP error in wordpress edit the .htaccess file in the wp-admin directory with the next lines of code:

1
2
3
4
5
6
7
8
#BEGIN Image Upload HTTP Error Fix
<IfModule mod_security.c>
<Files async-upload.php>
SecFilterEngine Off
SecFilterScanPOST Off
</Files>
</IfModule>
#END Image Upload HTTP Error Fix

PHP uploading large file sets

We must set
The php.ini file contains configuration settings for PHP, including parameters related to upload files, these properties are:

  • post_max_size: maximum size of data sent by POST.
  • upload_max_filesize: maximum size for uploading files.
  • max_execution_time: maximum execution time of each script in seconds.
  • max_input_time: maximum time to analyze the request for data.

First Method: Setting php.ini
The first way to enable the uploading of large files is to edit the file php.ini. Then, we open the file php.ini and change the desired parameters, in our case enable a maximum of 100 Mb to upload and up to 1000 seconds for execution_time:

; Resource Limits ;
max_execution_time = 1000
max_input_time = 1000
; Maximum size of POST data that PHP will accept.
post_max_size = 100M
; Maximum allowed size for uploaded files.
upload_max_filesize = 100M

Second Method: Setting. Htaccess
The second way is to change the settings with the help of the file. Htaccess, this create a file named. Htaccess at the root of your Web server, then put it into this file as follows:

php_value upload_max_filesize 100M
php_value post_max_size 100M
php_value max_execution_time 1000
php_value max_input_time 1000

Third Method: Setting the php script
The third way is to change the settings directly on our php script, to this end we will use the ini_set function that allows to overwrite the general configuration, then at the start of our script to be processed uploads place:

ini_set('post_max_size','100M');
ini_set('upload_max_filesize','100M');
ini_set('max_execution_time','1000');
ini_set('max_input_time','1000');