RSS

Tag Archives: htaccess

Protect website with htpasswd and htaccess

Sometimes we need to protect our website or website directories with username and password while we are working on development server. Password protect one or more directories with Basic HTTP Authentication using .htaccess. A .htpasswd file will be used to store login details.

Add following code into your .htaccess file

AuthType Basic
AuthName “My Protected Area”
AuthUserFile /path/to/.htpasswd
Require valid-user

Auth name: This name will be displayed in the login box when a user access your protected area for the first time.

AuthUserFile: you need to enter the full path of your .htpasswd file here. Use the following PHP script to find the full path of you .htpasswd file

<?php
$dir = dirname(__FILE__);
echo "<p>Full path to this dir: " . $dir . "</p>";
echo "<p>Full path to a .htpasswd file in this dir: " . $dir . "/.htpasswd" . "</p>";
?>
 
Leave a comment

Posted by on May 28, 2012 in Uncategorized

 

Tags: , , ,

Increase upload filesize in PHP from applicatoin

PHP calculates and displays the maximum file size that you can set based upon two PHP settings: ‘post_max_size’ and ‘upload_max_filesize’. Since ‘post_max_size’ is the limit for all the content of your post, many people choose ‘post_max_size’ to be a multiple of ‘upload_max_filesize’ to allow multiple files to be uploaded, but this is not essential. The upload module limits the size of a single attachment to be less than either post_max_size, or upload_max_filesize, whichever is smaller. The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size.

To increase maximum upload limit we need to change into PHP.ini file. Maximum file upload size that you can set based upon two PHP settings: ‘post_max_size’ and ‘upload_max_filesize’. Since ‘post_max_size’ is the limit for all the content of your post, many people choose ‘post_max_size’ to be a multiple of ‘upload_max_filesize’ to allow multiple files to be uploaded, but this is not essential. The upload module limits the size of a single attachment to be less than either post_max_size, or upload_max_filesize, whichever is smaller. The default PHP values are 2 MB for upload_max_filesize, and 8 MB for post_max_size.
But we don’t have access into PHP.ini file while we are using a shared hostings. Still you can increase maximum upload file size from your application level. There is two way to do that. One is using PHP code and another is by .htaccess file.

Using .htaccess

Add the below to your .htaccess file in your root directory.

php_value upload_max_filesize 10M
php_value post_max_size 10M

By PHP code

Add following codes into your settings.php file

• ini_set(‘upload_max_filesize’, ’10M’);
• ini_set(‘ post_max_size’, ’10M’);

I will prefer to use .htaccess file to increase upload file size. Also you need to increase maximum executoin time for last files upload

php_value max_execution_time 300 #(default in ms)

The PHP documentation states that the memory_limit setting also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size. If this is an issue, see the page on how to Increase memory available to PHP (3 methods)

 
Leave a comment

Posted by on December 28, 2010 in PHP

 

Tags: , ,