PHP Wrapper for Funnelback Frontends

Managed by | Updated .

This code is an extremely simple PHP wrapper example. It demonstrates a minimal viable implementation to request Funnelback results from the server side in a PHP environment. It should not be considered viable for production.

Please note that this example does not include cookie support and - as such - will not be usable in conjunction with Funnelback search sessions.

           // The base components for our request
           $protocol = "http://"; 
           $host = ""; 
           $base_path = "/s/search.html?"; 
           // Don't forget to input your collection name below
           $default_cgi_string = "collection=YOUR_COLLECTION_HERE&query="; 
           $url = $protocol . $host . $base_path;
           // Do we have a CGI string? This is an important check!
           if ($_GET) {
                // Rebuild our query string - do not filter the CGI params
                $url .= http_build_query($_GET); 
           } else {
                // More importantly, we set the default cgi string
                // if none is given. 
                $url .= $default_cgi_string;
           // Now let's init our cURL to fetch the results
           $curl = curl_init();
           curl_setopt_array($curl, array(
                   CURLOPT_RETURNTRANSFER => 1,
                   CURLOPT_URL => $url,
                   CURLOPT_TIMEOUT => 5
           // Execute
           $response = curl_exec($curl);
           // and close.
                // The response here contains the rendered HTML results
                echo $response; 
           } else {
                // You should take appropriate action here
                echo "<p>Something went wrong</p>";

Was this artcle helpful?