Thursday, 6 March 2014

Linux Access logs - List of Columns - Simple commands to view Server Logs

Linux Access logs - List of Columns - Simple commands to view Server Logs

When we run our website in Linux server, we must know about the linux access logs and error logs. Because with use of access log we get to know who is accessing our website and with use of error logs we get to know what types of error are coming in our website while running.

So, Access Logs/Error Logs are very important thing not for server admin but also for developer. Because sometimes website is very well developed by developer but due to server error, website is not performing well. If website is not working fine then it can effect the your users and directly it will decrease the annual income.

Get basic understanding of Server/Access logs. And if there is any issue with your server logs then get fixed ASAP. 

Following are the List of columns which are in Access Log

  • Remote Address – IP from which request was made
  • Remote User – Will bank for public pages
  • Date Time – timestamp as per server timezone
  • URL – HTTP request with  GET/POST/PUT/DELETE etc + Arguments + HTTP/HTTPS
  • Status – HTTP response code 
  • Response Size – size of server response in bytes
  • HTTP REFERRAL URL – Referral URL (if present)
  • User Agent – User agent as seen by server

Access log file location
cd /var/logs

Get the First column of log file
cat access.log | cut -d '"' -f1

Get the First colum of log file
cawk '{print $1}' cat access.log

PHP - Secure Ajax Call from Hackers - Example

PHP - Secure Ajax Call from Hackers - Example

Today, In all web application we use Ajax call to get the server data without refresh the full page. In this cases, we get required data from server without refresh the page.

For Example
In Registration Page, We want to validate the unique email address of user


Following the Simple Steps to do more Secure your Ajax Call.

1. Ajax Check - Ajax url must give Response when request is from ajax.
 
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&  strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') 
{
echo "Ajax Call";
} else{
echo "No Ajax Call";
}

2. Domain Check - Ajax url must give response, when request from your own server.
if(!empty($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER']=="WWW.mydomain.com/url")
{
 //Request from my server
}

3. Always use post Method 

4. Token System
 a) Create a token and encrypt  the data.
 b) Send with Ajax
 c) Before giving the result check the request with de-crypt