This simple tutorial allows you to set up a search form on your site powered by Google. Here’s how to do it.
1. Save a file called search.php on the root of your website with the following code:
2. Paste this code on your site wherever you want the search form:
<form action="/search.php" method="post">
Search: <input type="text" name="query"><br>
<input type="submit" value="Search">
Done! That’s all there is to it. Basically what happens is your search form sends the search phrase to the first script (search.php), which adds your domain name on the beginning, then does a search on Google. So if a user typed “honey badger” into the search box, the script would send them to a Google search for “site:yoursite.com honey badger”. This tells Google to search only “yoursite.com” for the given term. Of course, for this to work, Google has to have indexed your site already. If you are not sure if this is done, just do a search for “site:yoursite.com” (replacing yoursite.com with your real domain name). If you get results, then you are in the index.