Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create the file <code>querygoogle.php</code> in the same folder:</p> <pre><code>&lt;?php session_start(); // Here's the Google AJAX Search API url for curl. It uses Google Search's site:www.yourdomain.com syntax to search in a specific site. I used $_SERVER['HTTP_HOST'] to find my domain automatically. Change $_POST['searchquery'] to your posted search query $url = 'http://ajax.googleapis.com/ajax/services/search/web?rsz=large&amp;v=1.0&amp;start=20&amp;q=' . urlencode('' . $_POST['searchquery']); // use fopen and fread to pull Google's search results $handle = fopen($url, 'rb'); $body = ''; while (!feof($handle)) { $body .= fread($handle, 8192); } fclose($handle); // now $body is the JSON encoded results. We need to decode them. $json = json_decode($body); // now $json is an object of Google's search results and we need to iterate through it. foreach($json-&gt;responseData-&gt;results as $searchresult) { if($searchresult-&gt;GsearchResultClass == 'GwebSearch') { $formattedresults .= ' &lt;div class="searchresult"&gt; &lt;h3&gt;&lt;a href="' . $searchresult-&gt;unescapedUrl . '"&gt;' . $searchresult-&gt;titleNoFormatting . '&lt;/a&gt;&lt;/h3&gt; &lt;p class="resultdesc"&gt;' . $searchresult-&gt;content . '&lt;/p&gt; &lt;p class="resulturl"&gt;' . $searchresult-&gt;visibleUrl . '&lt;/p&gt; &lt;/div&gt;'; } } $_SESSION['googleresults'] = $formattedresults; header('Location: ' . $_SERVER['HTTP_REFERER']); exit; ?&gt; </code></pre> <p>And create the other file <code>search.php</code> in the same folder:</p> <pre><code>&lt;?php session_start(); ?&gt; &lt;form method="post" action="querygoogle.php"&gt; &lt;label for="searchquery"&gt;&lt;span class="caption"&gt;Search this site&lt;/span&gt; &lt;input type="text" size="20" maxlength="255" title="Enter your keywords and click the search button" name="searchquery" /&gt;&lt;/label&gt; &lt;input type="submit" value="Search" /&gt; &lt;/form&gt; &lt;?php if(!empty($_SESSION['googleresults'])) { echo $_SESSION['googleresults']; unset($_SESSION['googleresults']); } ?&gt; </code></pre> <p>Click the search button and the result are printed with echo <code>$_SESSION['googleresults'];</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload