Parse file without extension as php

If you have a file with PHP code and you have removed the extension for security purpose. Now you need to force the server that this is a php code, add the below code in .htaccess file in your root directory

<Files “action”>
ForceType application/x-httpd-php

“action” – This can be replaced with various regular expressions as well.


Installation | Laravel – A Basic Intro

As Laravel is becoming a glooming framework now with PHP, I would like to add a small introduction to Laravel along with basic installation steps.

First thing to do before starting with Laravel is we need to install composer. Composer is a dependancy management tool, which will manage the libraries which we need to include by itself (install/update library).

Please find the below link to do the installation of composer,

To verify whether composer is properly installed in your system, follow the below steps,

  • Open Command prompt,
  • Type the command “composer -V”

You should see the composer version something like below,

Composer version 1.1.3 2016-06-26 15:42:08

Why composer is required in Laravel?

You can install Laravel using composer as below,

In Laravel package we have a file called “composer.json” in the root directory, which will be having the list of dependancy files which needs to be included.

For manually installing Laravel doanload the laravel package and put it in any desired directory you need your project to be in and do follow the below commands to install it.

php composer.phar install
composer install

Setting up basic Environment Settings:

Once the dependancy files are updated. You can setup your environment by creating the .env file, which will be available in laravel root directory as “.env.example”. Just rename it to “.env” and change the necessary values in it.

First thing to change in it is the APP Settings,

Define thhe APP_ENV,  APP_URL as required.

APP_KEY – This key should be generated by running the below command,

php artisan key:generate

This will give you a key and it will be updated in the .env file.

NOTE : Make sure you have the .env file in your directory

Then you can create database and update the database details, cache, mail, etc in the .env file. Now you are ready to go with Laravel.

In next post you can learn about the basics of how Laravel works and how the interaction happens in the framework.

JQuery Datepicker – altField and altFormat

As I have seen lot of places were I am finding the date displaying incorrect. The most cases at that issue are, we would save the date in dd/mm/yyyy (most standard format) and when displaying use some other format. So there might me some conversion issue. Here comes the solution for it,

HTML Code :

This field is used to just show the date in UI

<input type=”text” class=”datepicker” id=”field-to-show” />

This field is used to save the date which is chosen

<input type=”hidden” name=”field-to-save” id=”field-to-save” />


JQuery Tweak:


dateFormat: ‘dd/mm/yyyy’, // Format used to show in UI

altField: ‘#field-to-save’, //ID of hidden field to save

altFormat: ‘dd-mm-yyyy’, // Standard format to save, which will be converting to correct time stamp



Sort an array by child value

$arr = array(
array(“translationID” => “1”,”locale” => “nl_BE”,”translation” => “U bent aangemeld”),
array(“translationID” => “2”,”locale” => “de_DE”,”translation” => “Sie sind angemeldet als”)

function cmp($a, $b) {
if ($a[“locale”] == $b[“locale”]) {
return 0;
return ($a[“locale”] < $b[“locale”]) ? -1 : 1;

Basic File Handling

Create a File

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //implicitly creates file

Open a File

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //open file for writing ('w','r','a')...

Read a File

$my_file = 'file.txt';
$handle = fopen($my_file, 'r');
$data = fread($handle,filesize($my_file));

Write to a File

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
$data = 'This is the data';
fwrite($handle, $data);

Append to a File

$my_file = 'file.txt';
$handle = fopen($my_file, 'a') or die('Cannot open file:  '.$my_file);
$data = 'New data line 1';
fwrite($handle, $data);
$new_data = "\n".'New data line 2';
fwrite($handle, $new_data);

Close a File

$my_file = 'file.txt';
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file);
//write some data here

Delete a File

$my_file = 'file.txt';

Convert url from uppercase to lowercase

First put this below code in .htaccess,

# force url to lowercase if upper case is found
RewriteCond %{REQUEST_URI} [A-Z]
# ensure it is not a file on the drive first
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule (.*) rewrite-strtolower.php?rewrite-strtolower-url=$1 [QSA,L]

Then add a newfile in the same directory of .htaccess file. and put the below contents to it.

if(isset($_GET['rewrite-strtolower-url'])) {
$url = $_GET['rewrite-strtolower-url'];
$params = http_build_query($_GET);
if(strlen($params)) {
$params = '?' . $params;
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/' . strtolower($url) . $params, true, 301);
header("HTTP/1.0 404 Not Found");
die('Unable to convert the URL to lowercase. You must supply a URL to work upon.');

Orelse try this,

Add this in httpd.conf file,

RewriteMap lower int:tolower

And this to .htaccess file,

RewriteRule [A-Z] ${lower:%{REQUEST_URI}} [R=302,L]

This will fix the issue.