There is a PHP file with a class and a function inside the class that connects to the file with the main class:
if(defined('VERSION')) define('version', VERSION); defined('version') OR die('Direct access is forbidden!'); class addClass extends mainClass { private function some_method() { return 'Result'; } } And there is an Ajax request in pure Javascript:
var request = new XMLHttpRequest(); var params = "filter=true"; request.open('POST', '/addclass.php', true); request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.onload = function(data) { console.log(this.responseText); } request.send(params); Question : How can I get the answer of the function some_method() ?
If you insert
if($_REQUEST['filter'] == true) { echo addClass::some_method(); } at the very beginning of the addclass.php file , even before the class addClass {} (it does not matter before if(defined('VERSION')) or after), then I get an error in the console
POST http://mydomain.com/addclass.php 500 (Internal Server Error)
And if I insert these lines after class addClass {} then as an Ajax-answer I get only
Direct access is forbidden!
if(defined('VERSION'))- do you use some kind of framework? If you want to bypass it, throw away the if and place your code after class declaration - splash58define('version', '1.0');- stckvrw