the5thace Posted July 2, 2013 Share Posted July 2, 2013 (edited) 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; ?> Edited July 2, 2013 by the5thace Quote Link to comment https://forums.phpfreaks.com/topic/279791-variable-out-of-scope-error-and-file_get_content_error/ Share on other sites More sharing options...
the5thace Posted July 2, 2013 Author Share Posted July 2, 2013 (edited) I have identified the misspelling of context and conext but the main Warning still persists. Edited July 2, 2013 by the5thace Quote Link to comment https://forums.phpfreaks.com/topic/279791-variable-out-of-scope-error-and-file_get_content_error/#findComment-1439059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.