Forum Moderators: coopster
For example, a script is called from within an iframe, which runs some code on a different server. The second server then needs to call a script on the first server but not output anything to the browser?
I could do this on the first server by reloading the page but don't want to do that because of negative effectes on the user experience.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec();
but not sure how to then get all the stuff in $dat into separate variables.
For example, say the script on the other server outputs:
<html>
<body>
1<br />
25<br />
</body>
</html>
How do I get the 1 and 25 into different variables ignoring all of the header information, etc.
Can't seem to find this in the manual...
Although curl will work, you might certainly be able to use file_get_contents() [php.net] or open a socket and read directly from the page as opposed to invoking curl. Not that curl doesn't work fine, it's just that you can accomplish many simple tasks without it.
$url = "http://127.0.0.1/htdocs/script.php?ID=".$ID;
$needle = 'Count:';
$contents = file_get_contents($url);
echo $contents;
if(strpos($contents, $needle)!== false) {
echo '<br />found';
} else {
echo '<br />not found';
}
but get a strange error appearing:
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:
Could this be caused by the fact I'm using my localhost or is it likely to be something else?
<html>
<head><title>Title</title></head>
<body>
<p>Here is the page you requested!</p>
<p>Here is the Count: 7</p>
</body>
</html>