| | |
Enter keyword in search box of any website using php script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 33
Reputation:
Solved Threads: 0
Hi all
I am a beginner and i was wondering can we write a code in PHP by which we can enter keyword in search box of any website and submit.
so there will be 2 inputs to this php function:
It will be a great help
thanks in advance
I am a beginner and i was wondering can we write a code in PHP by which we can enter keyword in search box of any website and submit.
so there will be 2 inputs to this php function:
PHP Syntax (Toggle Plain Text)
function enter_keyword($website_url, $keyword) { }
It will be a great help
thanks in advance
Are you talking about a 'web page' or an entire 'web site'. Because with a webpage you can just use file_get_contents() to retrieve the data then use regex to find the keywords. However, if you are talking about a 'website' or network of pages then that will require a bot that indexs the website to a database and the search form would check the database. Both ways I can help you just need to know which one.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
Join Date: Sep 2008
Posts: 33
Reputation:
Solved Threads: 0
•
•
•
•
Are you talking about a 'web page' or an entire 'web site'. Because with a webpage you can just use file_get_contents() to retrieve the data then use regex to find the keywords. However, if you are talking about a 'website' or network of pages then that will require a bot that indexs the website to a database and the search form would check the database. Both ways I can help you just need to know which one.
thanks for the reply
following needs to be done::
1.) I want to send a keyword for eg: 'knowing' to website for eg: "http://stagevu.com/" search box and submit it.
2.) then i want to return the url of first result from the result page.
i know that (2.) can be done using CURL but what about first.
thanks again for taking out your time for replying
jyotiu
Although you didn't entirely answer my question (scan the website or single webpage) I will assume you want to scan the website in which case will require a bot. I have recently written a bot to scan for site security holes and the bot template is as follows:
And to edit this, just place in the generate() function the code you want performed on each page. Also the only parts that should be modified are after the giant space.
Just a note on the theory behind this. The bot above will scan the website and index all the pages into a database then whenever somebody searches a website that is in the index then it can check the most relevent pages within the selected website. Alternatively you can piggy back off google.
php Syntax (Toggle Plain Text)
<? set_time_limit(0); function domain($domainb) { $bits = explode('/', $domainb); if ($bits[0]=='http:' || $bits[0]=='https:') { return $bits[0].'//'.$bits[2].'/'; } else { return 'http://'.$bits[0].'/'; } unset($bits); } if (isset($_GET['site'])) { echo '<head><title>Bot scanning website - '.domain($_GET['site']).'</title></head><body>'; } else { echo '<head><title>Bot scanner</title></head><body>'; } echo '<center><font size=5 face=\'arial black\'><b>PHP Bot Scanner</b></font><br><form method=\'get\' style=\'margin:0px; padding:0px;\'><input type=\'text\' name=\'site\' size=64 value="'.$_GET['site'].'"><input type=\'submit\' value=\'Scan\'></form></center>'; if (substr_replace($_GET['site'],'',3)=='ftp') { exit('You may not connect to the ftp protocole'); } if (!isset($_GET['site'])) { exit(''); } $_GET['site']=domain($_GET['site']); function url_exists($durl) { // Version 4.x supported $handle = curl_init($durl); if (false === $handle) { return false; } curl_setopt($handle, CURLOPT_HEADER, true); curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox curl_setopt($handle, CURLOPT_NOBODY, true); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); $connectable = curl_exec($handle); curl_close($handle); if (preg_match('/200 OK/i',substr_replace($connectable,'',30))) { return true; } else { return false; } } //below function will only get links within own domain and not links outside the site. function getlinks($generateurlf) { $datac=file_get_contents($generateurlf); preg_match_all('/(href|src)\=(\"|\')[^\"\'\>]+/i',$datac,$media); unset($datac); $datac=preg_replace('/(href|src)(\"|\'|\=\"|\=\')(.*)/i',"$3",$media[0]); $datab=array(); foreach($datac AS $dfile) { $generateurle=$generateurlf; if (!in_array(substr_replace($dfile,'',4),array('http','www.'))) { if (substr_replace($generateurle,'',0, -1)!=='/') { $generateurle=preg_replace('/(.*)\/[^\/]+/is', "$1", $generateurle); } else { $generateurle=substr_replace($generateurle,'',-1); } if (substr_replace($dfile,'',1)=='/') { if (domain($generateurle)==domain($generateurle.$dfile)) { if (in_array(strtolower(preg_replace('/(.*)[.]([^.\?]+)(\?(.*))?/','$2',basename($generateurle.$dfile))),array('html','htm','xhtml','xml','mhtml','xht','mht','asp','aspx','adp','bml','cfm','cgi','ihtml','jsp','las','lasso','lassoapp','pl','php','php1','php2','php3','php4','php5','php6','phtml','shtml','search','query','forum','blog','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','01','02','03','04','05','06','07','08','09','go','page','file')) || substr($generateurle.$dfile,-1)=='/' || !preg_match('/[\.]/i',basename($generateurle.$dfile))) { $datab[]=$generateurle.$dfile; } } } else if (substr_replace($dfile,'',1)=='.') { while (preg_match('/\.\.\/(.*)/i', $dfile)) { $dfile=substr_replace($dfile,'',0,3); $generateurle=preg_replace('/(.*)\/[^\/]+/i', "$1", $generateurle); } if (domain($generateurle)==domain($generateurle.'/'.$dfile)) { if (in_array(strtolower(preg_replace('/(.*)[.]([^.\?]+)(\?(.*))?/','$2',basename($generateurle.'/'.$dfile))),array('html','htm','xhtml','xml','mhtml','xht','mht','asp','aspx','adp','bml','cfm','cgi','ihtml','jsp','las','lasso','lassoapp','pl','php','php1','php2','php3','php4','php5','php6','phtml','shtml','search','query','forum','blog','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','01','02','03','04','05','06','07','08','09','go','page','file')) || substr($generateurle.'/'.$dfile,-1)=='/' || !preg_match('/[\.]/i',basename($generateurle.'/'.$dfile))) { $datab[]=$generateurle.'/'.$dfile; } } } else { if (domain($generateurle)==domain($generateurle.'/'.$dfile)) { if (in_array(strtolower(preg_replace('/(.*)[.]([^.\?]+)(\?(.*))?/','$2',basename($generateurle.'/'.$dfile))),array('html','htm','xhtml','xml','mhtml','xht','mht','asp','aspx','adp','bml','cfm','cgi','ihtml','jsp','las','lasso','lassoapp','pl','php','php1','php2','php3','php4','php5','php6','phtml','shtml','search','query','forum','blog','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','01','02','03','04','05','06','07','08','09','go','page','file')) || substr($generateurle.'/'.$dfile,-1)=='/' || !preg_match('/[\.]/i',basename($generateurle.'/'.$dfile))) { $datab[]=$generateurle.'/'.$dfile; } } } } else { if (domain($generateurle)==domain($dfile)) { if (in_array(strtolower(preg_replace('/(.*)[.]([^.\?]+)(\?(.*))?/','$2',basename($dfile))),array('html','htm','xhtml','xml','mhtml','xht','mht','asp','aspx','adp','bml','cfm','cgi','ihtml','jsp','las','lasso','lassoapp','pl','php','php1','php2','php3','php4','php5','php6','phtml','shtml','search','query','forum','blog','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','01','02','03','04','05','06','07','08','09','go','page','file')) || substr($dfile,-1)=='/' || !preg_match('/[\.]/i',basename($dfile))) { $datab[]=$dfile; } } } } unset($datac); unset($dfile); return $datab; } $loopurl['sites']=array($_GET['site']); foreach (getlinks($_GET['site']) AS $link) { if (!in_array($link,$loopurl['sites'])) { $loopurl['sites'][]=$link; } } unset($link); function generate($genurl) { $data=file_get_contents($genurl); //add there what you want to do with the page contents in the variable $data. } for ($loopid=0;isset($loopurl['sites'][$loopid]);$loopid++) { if (url_exists($loopurl['sites'][$loopid])) { foreach (getlinks($loopurl['sites'][$loopid]) AS $link) { if (!in_array($link,$loopurl['sites'])) { $loopurl['sites'][]=$link; } } unset($link); echo generate($loopurl['sites'][$loopid]); flush(); } usleep (5000); } echo '<br><b>Bot scan complete.</b></body>'; ?>
Just a note on the theory behind this. The bot above will scan the website and index all the pages into a database then whenever somebody searches a website that is in the index then it can check the most relevent pages within the selected website. Alternatively you can piggy back off google.
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
Join Date: Sep 2008
Posts: 33
Reputation:
Solved Threads: 0
okay let me explain again what i want to do.
I will create a simple php page which will have a input box and a submit button.
this input box will be use to insert any keyword. when a person will hit submit...on the back end... i need a script that will submit/post this keyword to a given websites searchbox/search page.
than i will scrap first results url and return to my page.
does that make sense?
I will create a simple php page which will have a input box and a submit button.
this input box will be use to insert any keyword. when a person will hit submit...on the back end... i need a script that will submit/post this keyword to a given websites searchbox/search page.
than i will scrap first results url and return to my page.
does that make sense?
Is this what your looking for? It uses google to search a selected site for selected keywords.
php Syntax (Toggle Plain Text)
<?php function search($search_term,$site) { global $dsite; $bits = explode('/', $site); if ($bits[0]=='http:' || $bits[0]=='https:') { $site=$bits[0].'//'.$bits[2].'/'; } else { $site='http://'.$bits[0].'/'; } $dsite=$site; $site=urlencode($site); $search_term=urlencode($search_term); $curl_handle=curl_init('http://www.google.com.au/search?hl=en&q=site%3A'.$site.'+'.$search_term.'&meta='); curl_setopt($curl_handle, CURLOPT_HEADER, false); curl_setopt($curl_handle, CURLOPT_FAILONERROR, true); curl_setopt($curl_handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox curl_setopt($curl_handle, CURLOPT_POST, false); curl_setopt($curl_handle, CURLOPT_NOBODY, false); curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,4); curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); $buffer = curl_exec($curl_handle); curl_close($curl_handle); $bufferb=strip_tags($buffer,'<cite>'); preg_match_all("/<cite>[^ ]+ - [0-9]+k - <\/cite>/",$bufferb,$match['url']); unset($bufferb); $match['url'][0]=preg_replace('/<cite>([^ ]+) - [0-9]+k - <\/cite>/','$1',$match['url'][0]); $bufferb=strip_tags($buffer,'<br><div>'); preg_match_all("/<div[^>]+>[^<]+<br>/",$bufferb,$match['des']); unset($bufferb); $bufferb=strip_tags($buffer,'<a>'); preg_match_all("/<a href=\"[^\"]+\"\ class\=l[^>]+>[^<]+<\/a>/",$bufferb,$match['title']); $id=0; while (isset($match['title'][0][$id])) { $match['title'][0][$id]=strip_tags($match['title'][0][$id]); $id+=1; } $result['url']=$match['url'][0]; $result['des']=$match['des'][0]; $result['title']=$match['title'][0]; unset($match); unset($buffer); unset($bufferb); unset($id); return $result; } echo "<form method='post' style='margin:0; padding:0;'><table border=0 cellpadding=0 cellspacing=0> <tr><td align='right'>Website:</td><td><input type='text' size=40 name='site'></td></tr> <tr><td align='right'>Search Term:</td><td><input type='text' size=40 name='searchval'><input type='submit' value='search'></td></tr></table></form><br>"; if (isset($_POST['searchval']) && strlen($_POST['searchval'])>=1) { $result=search($_POST['searchval'],$_POST['site']); $id=0; echo "<table border=0 cellspacing=0 cellpadding=0 width=640><tr><td bgcolor='#66CCFF'><table border=0 cellpadding=3 cellspacing=0><tr><td>". '<b>Website searched: '.$dsite.'<br> There were '.count($result['title'])." results found with the term '<i>".$_POST['searchval']."</i>'</b></td></tr></table></td></tr>"; while (isset($result['url'][$id]) && isset($result['des'][$id])) { echo '<tr><td><a href="http://'.$result['url'][$id].'"><font color=#0000FF>'.$result['title'][$id].'</font></a></td></tr><tr><td>'.$result['des'][$id].'</td></tr><tr><td height="16px"></td></tr>'; $id+=1; } echo "</table>"; } ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
![]() |
Other Threads in the PHP Forum
- Previous Thread: http authentication in php
- Next Thread: Mac address
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube







