Jump to content

Variable out of scope error and file_get_content_error


the5thace

Recommended Posts

I'm just trying to retrieve results using bing API. All I have done so far is copy the example for the bing user manual. https://skydrive.live.com/view.aspx?resid=9C9479871FBFA822%21112&app=Word&authkey=%21ANNnJQREB0kDC04 but I'm getting an error with the scope of the variable. The variable in question is $context
 

Warning: file_get_contents() [function.file-get-contents]: SSL: fatal protocol error in /home/msc2012/12254822/public_html/MetaSearchV1/bing_basic.php on line 35


Service Operation
 
<?php


$acctKey = 'xPx9I4rWqBBFRGO4+5aZai7x/KrqSMuM/jLIchClJ6I';
$rootUri = 'https://api.datamarket.azure.com/Bing/Search';
$contents =  file_get_contents('index.html');
//contents therefore has basic in it as words?


if ($_POST['query'])
{
 $query = urlencode("'{$_POST['query']}'");
 $serviceOp = $_POST['service_op'];
 $requestUri = "$rootUri/$serviceOp?\$format=json&Query=$query";
 // Encode the credentials and create the stream context.


$auth = base64_encode("$acctKey:$acctKey");


$data = array(


'http' => array(


'request_fulluri' => true,


// ignore_errors can help debug – remove for production. This option added in PHP 5.2.10


'ignore_errors' => true,


'header' => "Authorization: Basic $auth")
);
   
$context = stream_context_create($data); 
// Get the response from Bing.
$response = file_get_contents($requestUri, 0, $conext);
$jsonObj = json_decode($response); 
$resultStr = '';
foreach($jsonObj->d->results as $value) { 
    switch ($value->__metadata->type) { 
    case 'WebResult': $resultStr .= "<a href=\"{$value->Url}\">{$value->Title}</a><p>{$value->Description}</p>"; break; 
    case 'ImageResult': $resultStr .= "<h4>{$value->Title} ({$value->Width}x{$value->Height}) " . "{$value->FileSize} bytes)</h4>" . "<a href=\"{$value->MediaUrl}\">" . "<img src=\"{$value->Thumbnail->MediaUrl}\"></a><br />"; break; } }
$contents = str_replace('{RESULTS}', $resultStr, $contents);
}
echo $contents;        
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.