Runtime environment of a php function called through ajax

Runtime environment of a php function called through ajax

Hi,

I call a php function with a command like :

var result = $.post('/php/fonctions.php', { fonction : 'citation', data : lang}, function( data) {
        txt_citation.innerHTML = data.citation+" <strong>"+data.nom+"</strong>";
        }, "json");

In the file fonctions.php I have a line " $_POST["fonction"]($_POST["data"]); " to call my function. I tried with " call_user_func_array($_POST["fonction"], $_POST["data"]); " but it never work I I don't know why. If you can explain me why it's good but it's not the reason of this post.

In my function, I have an " require '/php/login.php'; ". This line doesn't work. I solved the problem with :

$env = '/volume1/web/hennus';
require $env.'/php/login.php';

I don't like this solution who work only on one specific server ! I tried with

$env = realpath('.');
require $env.'/php/login.php';

and I realized that funtion like realpath() don't work when called through ajax. It seems that I had other function who don't work as usual. For example, how to use php file functions when you don't know "where" you are ?

I suppose that the server create an special runtime environment (secure runtime environment ?) when called through ajax (from outside in other word). If " require " work, " require_once " seems not work...

Could you explain me what append exactly with the runtime environment where my php function will work (from a practical view - no need to understand exactly what append).

If you have example on :

How can I find the full path to use " require ", to use file functions and other things like that ?
How to easily debug my php function when called through ajax ? " echo $test " don't work as usual ;-)

I know the problem, I can imagine why but I don't understand it ;-)

Thanks for your help

Marc