Jump to content

Die on direct access


Morsusy2k

Recommended Posts

Okay so i have this main (index.php) file that loads a bunch of other php files.As you can already guess I want to make a page (for example) die when accessed directly...I don't want to use .htaccess. I guess I should do it like this:In my index.php inside body tags add:

<?php  define('ping', true);   echo ping; //just testing?>

And inside any other page that loads:

<?php    if (!defined('ping')) {    die('Hacking attempt...');   }  ?>

So that should work,right? But it does not..I guess its some kind of stupid mistake :S And just to mention I am not loading php files via php,i load them via JavaScript,is that making this problem?Thanks.

Link to comment
Share on other sites

If you're loading the files by ajax, then you are accessing them directly. An ajax request is like any other browser request, like typing in a URL or submitting a form. If you want to make it so that they should only be loaded by ajax then you may need to check the referer header to make sure the header contains a URL of one of the pages on your site. That's not a great solution though, because some browsers won't sent a referer header and then your site won't work for those.

Link to comment
Share on other sites

What you originally suggested will work if you use PHP to include files, but once the page is rendered you can't change it with PHP without a reload. You can add a querystring parameter when you load the file:

$('#menu1').click(function(){  $('#content').load('page.php?js');});

And then inside the file check if $_GET['js'] is set, but all they have to do to load the file is add that to the URL. There's not really a way to do that, since the ajax request is basically a normal browser request as far as the server is concerned it's difficult to distinguish an ajax request from anything else.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...