Jump to content

Variable out of scope error and file_get_content_error


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

$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;        
Edited by the5thace
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.