Showing posts with label Security. Show all posts
Showing posts with label Security. Show all posts
How to disable the browser back button navigation using javascript

How to disable the browser back button navigation using javascript

Hi, Today you will learn about "How to disable the browser back button navigation using javascript", In general, we don't use this type of requirement in the project.But is very useful in so many situations.

For example, we are doing in the online cart i.e an e-commerce platform so here after the placing the order and once the user checks out the order in his cart and payment completed it will redirect and shown the order success page after that user doesn't go back to the previous pages. So here we want to block the browser back button navigation.

So here in this situation we will use this code. if you searched on the internet you will find the code i.e
<script type="text/javascript">  
     window.history.forward();  
     function noBack()  
     {  
       window.history.forward();  
     }  
 </script>  
 <body onLoad="noBack();" onpageshow="if (event.persisted) noBack();" onUnload="">   
This code is not working properly. so I have found the solution to this problem. Just add the below script code on the file where the user doesn't go back from that file.
<script type="text/javascript">  
 (function (global) {   
   if(typeof (global) === "undefined") {  
     throw new Error("window is undefined");  
   }  
   var _hash = "!";  
   var noBackPlease = function () {  
     global.location.href += "#";  
     // making sure we have the fruit available for juice (^__^)  
     global.setTimeout(function () {  
       global.location.href += "!";  
     }, 50);  
   };  
   global.onhashchange = function () {  
     if (global.location.hash !== _hash) {  
       global.location.hash = _hash;  
     }  
   };  
   global.onload = function () {        
     noBackPlease();  
     // disables backspace on page except on input fields and textarea..  
     document.body.onkeydown = function (e) {  
       var elm = e.target.nodeName.toLowerCase();  
       if (e.which === 8 && (elm !== 'input' && elm !== 'textarea')) {  
         e.preventDefault();  
       }  
       // stopping event bubbling up the DOM tree..  
       e.stopPropagation();  
     };       
   }  
 })(window);  
 </script>  
Here you can check the demo.
Demo
* If you like this post please don't forget to subscribe TechiesBadi - programming blog for more useful stuff
How to stop direct URL access to images with htaccess

How to stop direct URL access to images with htaccess

Hi, Do you know how to prevent the direct URL access to the web?

In my current project, somebody has copied my whole images from the site with direct access. In this case, we lose the data and this data went to untrusted persons they definitely misuse our content.

To prevent this type of attack from the hackers to disable the direct URL access. This is a simple way to do by using the .htaccess file.
.htaccess
RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.ltd [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.ltd.*$ [NC] 
RewriteRule \.(gif|jpg|js|txt)$ /messageforcurious [L]

When anybody tries to access the direct URL it returns 403 but allows them to be displayed on the site.

This is a Rosi pov's rule it works great!. So taking rosipov's rule to redirect any direct request to {gif,jpg,js,txt} files to 'messageforcurious'

NOTE: it is possible that when you open some page with image and then copy that image's path into the address bar you can see that image, it is only because of the browser's cache, in fact that image has not been loaded from the server

In your localhost try this code
.htaccess
RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC] 
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC] 
RewriteRule \.(gif|jpg)$ - [F]
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff
How to disable the right click, copy text and view source in a website

How to disable the right click, copy text and view source in a website

If you want to secure your website with JavaScript no right click ,no copy text , block the view source in the browser (CTRL + U).

You are worked hardly to place the content in the your site. But some one easily stolen the content just copying from your website or from the view source and some experts may use right  click in your site and stolen the your documents links from your site also.

To Prevent these type of attacks from your website. Copy and paste the following code, and make sure it place in the above </HEAD>  tag.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>  
 <script type="text/JavaScript">  
  var message="NoRightClicking";  
  function defeatIE() {if (document.all) {(message);return false;}}  
  function defeatNS(e) {if   
  (document.layers||(document.getElementById&&!document.all)) {  
  if (e.which==2||e.which==3) {(message);return false;}}}  
  if (document.layers)   
  {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=defeatNS;}  
  else{document.onmouseup=defeatNS;document.oncontextmenu=defeatIE;}  
  document.oncontextmenu=new Function("return false")  
 jQuery(document).ready(function($){  
  $(document).keydown(function(event) {   
  var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();  
  if (event.ctrlKey && (pressedKey == "c" || pressedKey == "u")) {  
  return false;   
  }  
  });  
 });   
 </script> 

Download Demo
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff
How to disabled the right click on webpage by using jquery

How to disabled the right click on webpage by using jquery

If you want to disabled the right click on entire website or particular div.First you need to load the Jquery file
Disable the right click on entire web page
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>   
  <script type="text/javascript">   
   $(function () {   
   $(document).bind('contextmenu', function (e) {   
    e.preventDefault();     
   });   
   });   
  </script>
Disable the right click on perticular division (div tag)
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>  
 <script type="text/javascript">  
   $(function () {  
    $('.Container').bind('contextmenu',function(e){  
    e.preventDefault();  
    alert('Right Click is not allowed on div');  
    });  
   });  
  </script> 
Html code
 <div class="Container">  
   div content  
 </div>

* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff
How to prevent the downloading of entire website by using .htaccess

How to prevent the downloading of entire website by using .htaccess

These days  website copying is normal thing. So many websites are copied by using the Httrack website copier and also other tools are available for downloading the entire website easily.After downloading the entire website. 

Using these tools can even grab the pieces needed to make a website with active code content work offline.

To prevent the downloading of entire website using these website copiers. We need to write some code on the .htaccess file.It will check the user agent and stops the downloading from these major website copiers.

.htaccess file

Options -Indexes

RewriteEngine On 

RewriteCond %{HTTP_USER_AGENT} ^BlackWidow [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Bot\ mailto:craftbot@yahoo.com [OR] 

RewriteCond %{HTTP_USER_AGENT} ^ChinaClaw [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Custo [OR] 

RewriteCond %{HTTP_USER_AGENT} ^DISCo [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Download\ Demon [OR] 

RewriteCond %{HTTP_USER_AGENT} ^eCatch [OR] 

RewriteCond %{HTTP_USER_AGENT} ^EirGrabber [OR] 

RewriteCond %{HTTP_USER_AGENT} ^EmailSiphon [OR] 

RewriteCond %{HTTP_USER_AGENT} ^EmailWolf [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Express\ WebPictures [OR] 

RewriteCond %{HTTP_USER_AGENT} ^ExtractorPro [OR] 

RewriteCond %{HTTP_USER_AGENT} ^EyeNetIE [OR] 

RewriteCond %{HTTP_USER_AGENT} ^FlashGet [OR] 

RewriteCond %{HTTP_USER_AGENT} ^GetRight [OR] 

RewriteCond %{HTTP_USER_AGENT} ^GetWeb! [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Go!Zilla [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Go-Ahead-Got-It [OR] 

RewriteCond %{HTTP_USER_AGENT} ^GrabNet [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Grafula [OR] 

RewriteCond %{HTTP_USER_AGENT} ^HMView [OR] 

RewriteCond %{HTTP_USER_AGENT} HTTrack [NC,OR] 

RewriteCond %{HTTP_USER_AGENT} ^Image\ Stripper [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Image\ Sucker [OR] 

RewriteCond %{HTTP_USER_AGENT} Indy\ Library [NC,OR] 

RewriteCond %{HTTP_USER_AGENT} ^InterGET [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Internet\ Ninja [OR] 

RewriteCond %{HTTP_USER_AGENT} ^JetCar [OR] 

RewriteCond %{HTTP_USER_AGENT} ^JOC\ Web\ Spider [OR] 

RewriteCond %{HTTP_USER_AGENT} ^larbin [OR] 

RewriteCond %{HTTP_USER_AGENT} ^LeechFTP [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Mass\ Downloader [OR] 

RewriteCond %{HTTP_USER_AGENT} ^MIDown\ tool [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Mister\ PiX [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Navroad [OR] 

RewriteCond %{HTTP_USER_AGENT} ^NearSite [OR] 

RewriteCond %{HTTP_USER_AGENT} ^NetAnts [OR] 

RewriteCond %{HTTP_USER_AGENT} ^NetSpider [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Net\ Vampire [OR] 

RewriteCond %{HTTP_USER_AGENT} ^NetZIP [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Octopus [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Offline\ Explorer [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Offline\ Navigator [OR] 

RewriteCond %{HTTP_USER_AGENT} ^PageGrabber [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Papa\ Foto [OR] 

RewriteCond %{HTTP_USER_AGENT} ^pavuk [OR] 

RewriteCond %{HTTP_USER_AGENT} ^pcBrowser [OR] 

RewriteCond %{HTTP_USER_AGENT} ^RealDownload [OR] 

RewriteCond %{HTTP_USER_AGENT} ^ReGet [OR] 

RewriteCond %{HTTP_USER_AGENT} ^SiteSnagger [OR] 

RewriteCond %{HTTP_USER_AGENT} ^SmartDownload [OR] 

RewriteCond %{HTTP_USER_AGENT} ^SuperBot [OR] 

RewriteCond %{HTTP_USER_AGENT} ^SuperHTTP [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Surfbot [OR] 

RewriteCond %{HTTP_USER_AGENT} ^tAkeOut [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Teleport\ Pro [OR] 

RewriteCond %{HTTP_USER_AGENT} ^VoidEYE [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Web\ Image\ Collector [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Web\ Sucker [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebAuto [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebCopier [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebFetch [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebGo\ IS [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebLeacher [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebReaper [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebSauger [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Website\ eXtractor [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Website\ Quester [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebStripper [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebWhacker [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WebZIP [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Wget [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Widow [OR] 

RewriteCond %{HTTP_USER_AGENT} ^WWWOFFLE [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Xaldon\ WebSpider [OR] 

RewriteCond %{HTTP_USER_AGENT} ^Zeus 

RewriteRule ^.* - [F,L]

Download
* If you like this post please don’t forget to subscribe Techies Badi - programming blog for more useful stuff