Call the php script in php with return value

advertisements

I am trying to get a return value from a script which returns per echo "complete" or "error". First I tought I could get this working with the php function file_get_contents, but it returns my whole script, not only the things I am printing in the script. Then I believed in the cURL method, but it can't get it working....

The script which is called:

<?php
include("config.php");
print "complete";
?>

the script with my curl:

$url="caller.php";
$ch = curl_init(); //initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); //set the url
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //return as a variable
$response = curl_exec($ch); //run the whole process and return the response
curl_close($ch); //close the curl handle

echo "test". $response."|";

Why isn't this working? And how can I get it working?! FILE Method?


If you want to capture the echoed values of an included script, you can use output buffering:

<?php
ob_start();    // start output buffering
include("caller.php");
$returned_value = ob_get_contents();    // get contents from the buffer
ob_end_clean();    // stop output buffering
?>