title: Allow access to PHP file only through ajax on local server
body: <p>I have a website that needs to increment values in a database based upon user interaction. When users click a button a php script is called that increments the value. I'd like to protect this script from being accessed by outside scripts. Currently a user could write their own web page with a javascript function that hits the same php file repeatedly to blow up the value in the database. </p>
  
  <p>Here's my jquery code that does the incrementing:</p>
  
  <pre><code>jQuery(function(){
  $('.votebtn').click(function(e){
      var mynum = $(this).attr('id').substring(0,5);
      $.ajax({
              url:"countvote.php",
              type:"GET",
              data: { 
                  thenum:mynum
              },
              cache: false,
              success:function(data) {
                  alert('Success!');
                  }
              }
          });
  });
  });
  </code></pre>
  
  <p>How would I go about making it so that only a call from ajax/jquery on the local server can access 'countvote.php'? If that's not the correct way to go about it, I'm open to any suggestion that will prevent my php script from being abused by outside scripts.</p>