Last active
September 20, 2019 16:07
-
-
Save diguinhorocks/4237748 to your computer and use it in GitHub Desktop.
Simple Google Custom Search API requester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en-US"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<form action="search.php" method="GET"> | |
<label for="">Pesquisar: </label> <input type="text" name="q" /> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Request | |
{ | |
protected $url; | |
protected $request; | |
protected $response; | |
protected $curl; | |
public function __construct(){ } | |
public function setQuery($query) | |
{ | |
$this->query = $query; | |
return $this; | |
} | |
public function go() | |
{ | |
$this->curl = curl_init(); | |
curl_setopt( $this->curl , CURLOPT_URL , ltrim( $this->queryURL() . '&q=' . urlencode($this->query) ) ); | |
curl_setopt( $this->curl , CURLOPT_SSL_VERIFYPEER , false ); | |
curl_setopt( $this->curl , CURLOPT_RETURNTRANSFER , 1 ); | |
$this->response = curl_exec($this->curl); | |
curl_close($this->curl); | |
return $this->getResponse(); | |
} | |
public function getResponse() | |
{ | |
header('Content-Type: application/atom+xml'); | |
echo $this->response; | |
} | |
protected function queryURL() | |
{ | |
return <<<URL | |
https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={your_cx}&alt=atom | |
URL; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'Request.php'; | |
$c = new Request(); | |
echo $c->setQuery($_GET['q'])->go(); |
Hello diguinhorocks, i was googleing and i found that u put your KEY.
If i want i can take your key and make my searchs.
Sorry for my english.
@alkchofa thanks! I didn't even remember about this gist anymore.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Daer Sir ,
I have use Simple Google Custom Search API but as search any thing in search box . we directaly open request.php