0

I have a PHP file called load.php I load content from asynchronously with JavaScript on my website example.com.

I want to redirect the user off the page if they try to go to example.com/load.php directly, but still return data if it's being requested through my JavaScript. How do I do this?

<?php 

//load.php

// Redirect user if they try to access example.com/load.php directly. Only accept asynchronously calls.

echo "example";

?>

<script>

var load = {
  url: 'https://example.com/load.php?q=example',
  type: "GET",
  success: function( data ) {
        console.log(data);
  }
};
$.ajax( load );

</static>
Steve Alereza
  • 133
  • 1
  • 8

0 Answers0