-3

I have the following code

class Flickr { 
    private $apiKey = 'YOUR API KEY HERE'; 

    public function __construct() {
    } 

    public function search($query = null) { 
        $search = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apiKey . '&text=' . urlencode($query) . '&per_page=50&format=php_serial'; 
        $result = file_get_contents($search); 
        $result = unserialize($result); 
        return $result; 
    } 
}

My web host does not allow me to use file_get_contents. How can I use curl instead?

Xtreme
  • 1,601
  • 7
  • 27
  • 59

1 Answers1

0

Something like this

<?php
    class Flickr { 
    private $apiKey = 'YOUR API KEY HERE'; 

    public function __construct() {
    } 

    public function search($query = null) {
    $url = 'http://flickr.com/services/rest/?method=flickr.photos.search&api_key=' . $this->apiKey . '&text=' . urlencode($query) . '&per_page=50&format=php_serial';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL,$url);
    $result=curl_exec($ch);
    //echo $result;//Your response
    return $result;
    }
  }
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126