How to change the php version for the console

Many a times when you view the php version in the browser by displaying the phpinfo() information and the php version that is displayed when you see by typing the command “php -v” in the console or command prompt, You will notice that there is difference in the two.

So how  to set the php version same as the version that you see in your phpinfo( ) function in the browser.

Step 1: Find the path to the executable of the php from the phpinfo() displayed in the browser. For example, if you have ampps installed you will find the path as “/Applications/AMPPS/php-7.1/bin/php”. 

Incase you have multiple version of php configured then choose the binary/executable path to the required version of php.

For example for php5, the path would be “/Applications/AMPPS/php5/bin/php”.

Step 2: Setting the php version for the console

Once you have decided upon the required php version for your console application execute the below command.

alias php=’/Applications/AMPPS/php-7.1/bin/php’ => This will set your php version to 7.1 for you console command line instruction.

Similarly for php5

alias php=’/Applications/AMPPS/php5/bin/php’

To make this work,You need to double check the location of the required php executable path, then only it will work. If you don’t have the required version installed. you could installed it as per your need and the operating system you are using.

 

How to download latest copy of a file from gitlab branch

I had code on my gitlab repository, Another person is also working on the same code . He had committed , pushed and merged his changes on the master branch. Now i just have to update only one file in my local working copy.

So this is possible by using the below two command.

git fetch
// git fetch will download all the recent changes, but it will not put it in your current checked out code (working area).

git checkout origin/masterpath/to/file
// git checkout <local repo name (default is origin)>/<branch name> — path/to/file will checkout the particular file from the downloaded changes (origin/master).

You can also pull specific files to your working copy from another branch as well. You just need to replace “origin/master” with your desired branch name.

When you fire git status command

git status
// it will show the fetched files as modified

issue with submit form in ajax success response

Usually when we try to submit the form after ajax call on success response, the form does not’t get submitted.

Like for example in below code:-

$.ajax({
type : “POST”,
url : “to/some/url”,
data : {
userName:userName,
mobileNumber:mobileNumber,
otp:otp
},
dataType : “json”,
success : function(data)
{
if(data.result == true) {
jQuery(“#form_id”).submit();
}else {
return false;
}
}
});

Now why this occur. Since you are calling the submit function from the ajax response, you need to remove the “submit” handler before submitting the form again. I.E. You need to submit the form without doing the ajax call again. Refer below:-

$.ajax({
type : “POST”,
url : “to/some/url”,
data : {
userName:userName,
mobileNumber:mobileNumber,
otp:otp
},
dataType : “json”,
success : function(data)
{
if(data.result == true) {
// Submit this form without doing the ajax call again
jQuery(“#form_id”).unbind().submit();
}else {
return false;
}
}
});

 

unicode issue in Perl CGI

When some special character(or other language data) is displayed as ‘? ? ? ? ?’ in browser, then you have to make the following change.

1.In your table set the collation of the field that is to be displayed as “Binary”.

If this does not work then you can try the below option in your cgi script

2. Set the meta-type in your templates file as

“<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />”.

If the above two does not work,then try the third option.

3.

use Encode qw(encode decode);

my $text = decode (‘utf8’, $value_to_be_decoded);


To calculate date difference between two given dates

function timeDifference(startDate,endDate)
{

date1 = startDate;
date2 = endDate;

laterdate = date1.split(“-“);
laterY=laterdate[0];
laterM=laterdate[1];
laterD=laterdate[2];

earlierdate = date2.split(“-“);
earlierY=earlierdate[0];
earlierM=earlierdate[1];
earlierD=earlierdate[2];

var laterdate = new Date(laterY,laterM,laterD);
var earlierdate = new Date(earlierY,earlierM,earlierD);

var difference = laterdate.getTime() – earlierdate.getTime();

var daysDifference = Math.floor(difference/1000/60/60/24);
difference -= daysDifference*1000*60*60*24
var hoursDifference = Math.floor(difference/1000/60/60);
difference -= hoursDifference*1000*60*60
var minutesDifference = Math.floor(difference/1000/60);
difference -= minutesDifference*1000*60
var secondsDifference = Math.floor(difference/1000);

return daysDifference;

}