Page 1 of 1

Searching a URL

Posted: Mon Sep 18, 2006 10:03 am
by GavW
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey all!

Was wondering if anybody could help me with this problem. I am attempting to search a URL for specific criteria and display the results of the search on the same page.

I have two files which I am working with: Index.php and WebSearch.inc.php class.

Index.php consists of the following form and results area:

Code: Select all

<?php
define ("AUTHOR", "Me");
require_once("WebSearch.inc.php");

$search = new WebSearch ();
?>

<form method="GET" action="<?=$_SERVER['PHP_SELF']?>">
	<div id="searchBox">
		<table id="searchDetails">
			<tr><td>Search Term</td><td><input class="text" name="term" type="text" value="some criteria" /></td></tr>
			<tr><td>Website</td><td><input class="text" name="url" type="text" value="http://website.com" /></td></tr>
			<tr><td>Search Depth</td><td><select name="depth">
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3" selected>3</option>
							<option value="4">4</option>
							<option value="5">5</option>
						     </select></td></tr>
		</table>		
		<input type="submit" value="start search" />
	</div>
	</form>

<?php $results = $search->return_result(); ?>
<h2>Showing <?=count($results)?> results</h2>
	<div id="resultsBox">
<?php foreach ($results as $result) { ?>
		<div id="result">
		<h3 class="title"><?=$result['title']?></h3>
		<em class="date"><?=$result['date']?></em>
		<p class="desc"><?=$result['content']?></p>
		<span class="url"><?=$result['url']?></span>
		</div>
<?php } ?>
The WebSearch.inc.php class I have managed to get this far:

Code: Select all

<?php

class WebSearch
{
	
	public function set_url ($url) 
	{
	
	}
	
	public function set_term ($search)
	{
	
	}
	
	public function return_result ()
	{
		$result = array();
		
		/* Fake Results */
		for ($i=0; $i<10; $i++) 
		$result[$i] = array (
						"title"		=> ($i+1).": Page Title",
						"date"		=> "Date Found: 15.08.06 00:00:00",
						"content"	=> "Content. More content. Some more content.",
						"url"		=> "http://example.domain.com/url"
					  );
		return $result;
	}
}

?>
Would somebody be able to advise me about which direction that I need to take?

Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Sep 18, 2006 1:52 pm
by akimm
I've been told by many that PHP_SELF is very dangerous, because of something called cross-site-scripting.

I was told this by Feyd, so I think its valid lol. Be aware of that.

an idea for searching a page contents is either create info seperators then explode them into an array which can be read and sorted by the no pun intended array of array functions.