RSS

Tag Archives: php

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>";
?>
Advertisements
 
Leave a comment

Posted by on May 28, 2012 in Uncategorized

 

Tags: , , ,

How to get Longitude and Latitude from Address using PHP

Couple of days ago I have worked with Google Map to do search pharmacy. Basically requirement is, user will search with zip code and the result will display all the pharmacy with a certain radius of the zip code. After doing some research I found, this can be search with with latitude and longitude (I won’t discus about this today, I will write about this in another post). Entering latitude and longitude by the user won’t be a smart application, so I plan to get the latitude an longitude from the given address.

Google provide example to identify latitude and longitude from address with JavaScript. But I need it from PHP code. After spending some time on Google I found the solution 🙂

Here I am going to find latitude and longitude of my current office

$jsondata=file_get_contents(‘http://maps.google.com/maps/api/geocode/json?address=house+16+road+7+Baridhara+Dhaka+Bangladesh&sensor=false&#8217;);

$output= json_decode($jsondata);

$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng;

echo “Latitude : “.$lat;
echo “Longitude : “.$long;

My example for JSON data. To get XML data, you just need to use xml instead of json. Do not use any space in address parameter, just use plus (+) sign here.

For more details visit this page The Google Geocoding API

 
Leave a comment

Posted by on May 3, 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: , ,

Configure CURL with XAMPP

Please do the following step to configure CURl XAMPP.

For current php version

  1. Open xampp location/apache/bin/php.ini
  2. Uncomment the following line in the “Windows Extensions” section: extension=php_curl.dll
  3. Restart apache

For all version of php please enable the php_curl.dll extension for the following files

  1. xampp location/apache/bin/php.ini
  2. xampp location/php/php5.ini
  3. xampp location/php/php.ini
  4. xampp location/php/php4/php.ini
  5. xampp location/php/php4/php4.ini
  6. Restart apache
 
5 Comments

Posted by on August 26, 2008 in Installation

 

Tags: , , ,