title: How to protect the .php file with JSON object when accessed through url in the browser
body: <p>I hope that this is not too difficult, so here is a story, I have created a simple process which is being sent as JSON object when requested, but for security reasons, would really like to protect (403) the content of the file if it is accessed by placing a full URL to it in the browser. </p>
  
  <p>Here is a script inside my ajax.php</p>
  
  <pre><code>&lt;?php
  $image = array(
  "/trial/images/1.png",
  "/trial/images/2.png",
  "/trial/images/3.png",
  "/trial/images/4.png"
  );
    $msg = array(
      'status' =&gt; 1,
      'message' =&gt; 'Remember to +1',
      'html' =&gt; '&lt;p&gt;Thank you for downloading our software &lt;img src="'. $image[array_rand($image)] .'" width="80" height="80" alt="Thank You"&gt;&lt;/p&gt;'
    );
    echo json_encode($msg);
  ?&gt;
  </code></pre>
  
  <p>and here is a script of the function that I am using to POST with ajax into that file to obtain JSON object out.</p>
  
  <pre><code>function custom_reminder(aElem){
      theLink=$(aElem).attr("href");
      $.ajax({
          type:"POST",
          url:"/includes/ajax.php",
          data:"action=reminder&amp;thepath="+theLink,
          dataType:"json",
          error:function(){window.location=theLink;},
          success:function(msg){
              if(msg.status == 1) {
                  display_reminder(msg.html,theLink);
              }else{
                  custom_message(msg.message,"error");
                  }
          }
      });
  }
  </code></pre>
  
  <p>Please help</p>