Showing posts with label htaccess. Show all posts
Showing posts with label htaccess. Show all posts

Tuesday, November 13, 2007

Disabling magic quotes in PHP

How to disable magic quotes




You cannot disable magic quotes from .htaccess or php.ini, only from apache httpd.conf file.

You can use PHP to disable magic quotes at runtime. Here is the function:

if (get_magic_quotes_gpc()) {
function
stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);

return
$value;
}

$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}

This function will strip slashes for all REQUEST values. If you make SQL queries with these values, you have to use mysql_real_escape_string function in order to prevent sql injection.


Disabling magic quotes, using Apache and PHP

Tuesday, October 16, 2007

Change upload file size apache

How to change the PHP maximum upload file size



The default maximum upload size for files is 2MB. If you have access to .htaccess files, you can change the maximum upload size from there. Here is what you should write in .htaccess files for apache:

php_value max_execution_time 1200
php_value memory_limit 30M
php_value post_max_size 10M
php_value upload_max_filesize 10M

In the first line you increase maximum execution time from 30 seconds (default) to 1200 seconds. This way if the file is large, you won't get a timeout browser error.
In the second line you increase memory limit to 30MB.
The third line increases post maximum size to 10MB.
And the last line increases upload maximum filesize to 10MB.

Tuesday, October 9, 2007

Permanent redirect to www domain

You have a domain anydomain.com, and you want a permanent redirect (301) to www.anydomain.com. You can do this using a .htaccess file. Here it is:

RewriteEngine on
RewriteCond %{HTTP_HOST}!^www.anydomain.com
RewriteRule ^(.*)$ http://www.anydomain.com/$1 [R=301,L]

So if someone types anydomain.com, he will be redirected to www.anydomain.com. easy.