Set up site search powered by Google

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:

$query="site:{$_SERVER["SERVER_NAME"]} ".$query;


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 “ honey badger”. This tells Google to search only “” 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 “” (replacing with your real domain name). If you get results, then you are in the index.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s