PHP basic search engine [iframe]

Lets create a script that will let you search any of the popular search engines that use the GET method. Examples: Google, Yahoo, Bing etc. This script will display an iframe for your search service anywhere on your page. You can also make it so Google searches through your website only. Let’s get started:

Bais HTML form:

<form method="GET" action="search.php">
<input type="text" name="q" value="Search"> <input type="submit" value="Search">
</form>

How it works:

This will create an input that will let the user enter the search term. The submit button will post the information in the input area to search.php.

search.php:
<?php
$q = $_GET['q']; //get it from the form
echo '<iframe src="http://www.google.com/search?q='.$q.'"></iframe>'; //embeds iframe for search results from GOOGLE.
?>

How it works:

Using the GET method this script will GET the $q that was posted earlier using the HTML form. Using echo we show an iframe. This iframe will show the search results from Google on your website. This is achived by replacing the ?q variable of the search engine and adding $q which is the search term. Some other sources for search engines:

Yahoo - http://search.yahoo.com/search/?q=&#8217;.$q.’

Bing – http://www.bing.com/search?q=&#8217;.$q.’&go=

Ask.com – http://www.ask.com/web?q=&#8217;.$q.’&search=&qsrc=0&o=0&l=dir

About these ads

About Eating Sharks
Born, etc. twitter.com/_shahz

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: