How to use “grep” command in linux or macos to find text inside all files in a folder and including subdirectories
Command for the same is grep -rl "string to search" /absolute-path/to/folder/
-r (or –recursive) option is used to traverse also all sub-directories of /path
-l (or –files-with-matches) option is used to only print filenames of matching files
-i ( for ignore case sensitive)
If you’re looking for lines matching in files, then use the below command
grep -Hrn "string to search" /absolute-path/to/folder/
-H causes the filename to be printed (implied when multiple files are searched)
-r does a recursive search
-n causes the line number to be printed
/absolute-path/to/folder/ can be . (dot) to search in the current directory
Many a time you have to host your website on multiple server such as load balancer to server high traffic website. It is obvious that if i have a load balancer or multiple servers in use, the user’s session is coming from 1 server so if the user is pushed to say server 2 or server 3 then does that mean the user’s session will expire or how to make it work as normal?
I have multi-session checks, so if a user logs-in from a different location it will auto sign them out like we see on bank websites. And this will affect the user journey and create issue to the users? Is there anything I need to do at the database level?
Yes you can do it by using custom session management using MySql or any other database.
But sometime, the server configuration doesn’t allow to overwrite the server default session handler, Hence you need to go with some different approach.
Option 2: The way i found the solution.
I created a session handler class using mysql database, create method to start, write, read, unset and destroy the session variable.
Below is the example usage of the same.
Usage Example Just include this file at the top, where you want to manage the session using session data
require_once ‘handleSession.php’; // Make sure to set the Mysql Database credential appropiately
To set session data in DB
Case 1: Set a single session data, pass the key and value in array $cstmSessionHandler->cstm_sess_write(array(‘developer1’=>’1vinod’));
Case 2: To set two dimensional session data, pass the key and value in array as below $newData[‘aaa’][‘ffff’] = ‘1111’; $newData[‘aaa’][‘bbb’] = ‘222’; $cstmSessionHandler->cstm_sess_write($newData);
To read session data
Case 1: To read only a single session variable Pass the session key. $sessionValuesArr = $cstmSessionHandler->cstm_sess_read(‘aaa’);
Case 2: To read all the session which are active. Dont pass any argument $sessionValuesArr = $cstmSessionHandler->cstm_sess_read();
To unset specific session variable $cstmSessionHandler->cstm_sess_unset(‘aaa’);
To destroy all the session variable $cstmSessionHandler->cstm_sess_destroy();
You can download the source code and example from gitlab
Normally when you use contact form 7 plugin , for dropdown select option, there is no option to set blank value for the first option to validate the select field.
For example, what we have in wordpress contact form 7
But in actual scenario, i want to display the label for the first option as “–Select Value–” with empty value.
To make the same change, you can use the dropdown code as below
[select* your_field_name_ class:form-select class:required first_as_label “–Select Value–” “Yes” “No”]
In the above code “first_as_label” is important parameter. It instruct the plugin to use the first option as label with default empty value. So the generated output look as below
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.
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/master — path/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
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;
}
}
});
<FilesMatch “\.(ttf|otf|eot|woff|js|css|woff2)$”> # Type all extenstion that you want to allow
<IfModule mod_headers.c>
Header Set Access-Control-Allow-Origin “*”
</IfModule>
</FilesMatch>