Lacrifilm Lacrifilm - 1 year ago 85
PHP Question

Receive PHP code with an POST request

I need to send a POST request to another file called

, for this I try this code below:

$url = 'global.php';
$data = array('stack' => 'overflow');

$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);


This is the
file that should process the request:

echo 'exists';
echo 'error';

The problem is that instead of the command
var_dump ($ result);
show exists, it shows the PHP code? how can I solve this problem?

And why when I try to do the same thing using
it returns me the text exists and not PHP code?

Answer Source

You should use full url, to process php file through server.

$url = '';

AJAX call is made from browser, to absolute URL, thats why You are getting desired response.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download