user4585803
user4585803

Reputation:

How to make file only accessible by JQuery .load

I have written a php file, but I only want to have it accessible by JQuerys .load function.

So on the one page I use .load to include the content of the php file in another file, but when I directly move to the url of the php-file I load, it works as well, but I don't want that..

My Code for the load is:

$('#loader').load('secretFolder/secretFile.php');

whereas loader is a div for the content loaded. So when I no go to example.com/secretFolder/secretFile.php there should be an error, but it should the .load should still work.

I tried to set like a global variable on index.php and then check for it in secretFile.php, but that didn't work.

Please help...

Upvotes: 0

Views: 408

Answers (1)

nameless
nameless

Reputation: 1521

You need to check for AJAX request in your secretFile.php, so this should work:

if( empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) &&
strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) != "xmlhttprequest"){
    die("ERROR");
}

By this, you don't need to define any variables or something.

Upvotes: 4

Related Questions