Morsusy2k Posted February 22, 2013 Share Posted February 22, 2013 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 More sharing options...
justsomeguy Posted February 22, 2013 Share Posted February 22, 2013 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 More sharing options...
Morsusy2k Posted February 22, 2013 Author Share Posted February 22, 2013 I'm loading them via jQuery actually, like this: $('#menu1').click(function(){ $('#content').load('page.php'); }); Link to comment Share on other sites More sharing options...
justsomeguy Posted February 22, 2013 Share Posted February 22, 2013 Right, that's an ajax request. Link to comment Share on other sites More sharing options...
Morsusy2k Posted February 22, 2013 Author Share Posted February 22, 2013 Ouch,so its not possible to do what I wanna achieve? Is it possible to do a file load via php without reloading? Link to comment Share on other sites More sharing options...
justsomeguy Posted February 22, 2013 Share Posted February 22, 2013 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 More sharing options...
Morsusy2k Posted February 22, 2013 Author Share Posted February 22, 2013 Okay,so it can't be done the way i need it..Thanks for answering anyways Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now