pTutorial

New way to learn PHP Example

How to make custom search engine

Custom Search

In this section we will learn, how to create custom search engine with the help of PHP header function.

Custom Search example

<html>
<body>
<form action="#" method="post">
<input type="text"  name="k" />
<input type="submit" name="sub" value="Select" style="display:none;" />

</form>
<?php
if(isset($_POST['sub']))
{
$mainUrl="http://www.google.com/";
 $searchData=trim($_POST['k']);
if($mainUrl == "") 
{
echo "Please select fruit";
}
else	
{
$url="site:http://www.ptutorial.com/";
$a="$mainUrl.#q=$url$searchData";
echo $a;
header("Location: $a");
exit;
}
}
?>
</body>
</html>

Explanation

In order to create custom search, first create simple HTML form with one input field and submit button. Submit the form with the help of Java script.

You can simply submit the form without using any Java Script, In that case we are using Java Script to submit the form.

After that get value from text field and concatenate with Google and your custom website and finally redirect the complete URL with the help of header function as shown in the above example.


QUOTES OF THE DAY

Wonder is the first cause of philosophy.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER