View Full Version : Making PHP for search engine...

01-26-2003, 07:43 PM
If anyone can help I'd appreciate it, I'm trying to make a search engine in PHP. I had several questions.

I'm a bit confused about "get" should I use this instead of "post"?

Should the results be stored in an array? I wanted to make 25 results show per page, with a <<Next and <<Back button.

I'm going to try and make each result "row" alternating colors (Like these forums) Is there an easier way to do this than write seperate HTML for two rows instead of just one?

Any help would be appreciated, I'm trying to get this thing done ASAP, and I'm a virtual newbie to PHP :(


01-26-2003, 11:33 PM
I wouldn't recommend trying to write a full out program in PHP right from the start if you are new to PHP and especially in a hurry. That's a recipe for disaster.

Use a free ready made script if you are in a hurry.


And yes you can use the "get" method if you wish for the visitors to be able to bookmark the search results so they can go back to them later. The get method simply adds the values passed in the URL.

01-26-2003, 11:50 PM
Thanks Spookster, I was wondering about that:)

Hoping I wouldn't need a complicated script to let people bookmark results etc, didn't realize it was that simple. :thumbsup:

01-27-2003, 05:02 AM
Ok this may be a dumb question...

When I test what I have so far, say I type in "internet", and press search...

It will take me to my search.php and say:

Sorry, there were no results for \"internet\"

Is there any way to make it display what I typed in, without the backslash code?


01-27-2003, 05:23 AM
Originally posted by nickbarresi
Is there any way to make it display what I typed in, without the backslash code?

Yes of course there is

01-27-2003, 11:26 AM
so helpful spook ;) (don't worry about him... he's getting old ;))

Edit the code for that page, and use the stripslashes() function :)

www.php.net/stripslashes for more info :)


01-27-2003, 08:44 PM
Ah, thank you that worked perfectly:)

01-27-2003, 09:52 PM
Originally posted by Jeewhizz
so helpful spook ;) (don't worry about him... he's getting old ;))

Edit the code for that page, and use the stripslashes() function :)

www.php.net/stripslashes for more info :)


Hey there cheezwhiz you better respect your elders! Didn't your mum(im assuming that's how you say mom in england) teach you nothing? :D

I was simply answering the question. If it were asked...."How do I...?" then I would have answered how. :)

And get out of my forum before I zap you with my mod gun. :)~

01-28-2003, 08:31 PM
Ok guys new question,

I'm adding a column "hits" to my database, which will keep track of how many times a particular link has been clicked through.
(Each row in database are links to sites... title, description, and URL, and hits)

Is there any way I can accomplish this in PHP? And if so, could you explain! :D

So in english:

When link clicked, add 1 to "hits" where url = link....or something:)

If I had a PHP/English dictionary, I'd be set, but I don't, so any help is greatly appreciated !

01-28-2003, 10:40 PM
Make a redirecting script that serves as an intermediary layer between your list of URLs and the target site. You pass the URL to be later send to as a GET parameter to the redirecting script, which does nothing else than make a quick connect to your database, and updates the "hits" value associated with that URL. After that, you redirect with the

header("Location: " . $absoluteURL);

function. That's it.

01-28-2003, 11:39 PM
Thanks Mordred:)

But I'm a bit confused,

What equals the $absoluteURL?

Also, what actually re-directs the page? The header function?

Thanks :)

01-29-2003, 12:12 AM
Originally posted by nickbarresi
What equals the $absoluteURL?

IIRC the specifications for HTTP require the URL of a "Location" response header to be an absolute URL. Most clients (aka browsers) are capable of resolving a relative URL, so you might not notice "breaching" the specs, but they are not required to do so. And to answer your question (:D):

An absolute URL contains the protocol and the host name, like


Whereas a relative URL is anything that's applied relatively to a host name, like


...so the actual URL depends on the point from where you resolve this path, thus it is an relative URL. If you really want to know more about it you can read the full specs at rfc-editor.org, but unless you're either very curious about the underlying technology or enjoy reading car insurance policies, you might find those RFCs a little boring... you have been warned. :D

Also, what actually re-directs the page? The header function?

Hmmh... erh... well... it's... you, the developer. :D
No seriously, your PHP script sort-of triggers the redirection, but the actual process of fetching another page is carried out by the client (aka browser). That's an important issue to know, unfortunately you see sometimes code samples like this:

if ( !userIsAuthorized() ) {
// redirect the cracker to the login screen
header("Location: " . $loginPage);
} // <- don't do this

which misses an essential part - to include a die() or exit() statement after the redirection to terminate the script ultimately.
Because otherwise someone could easily build a HTTP client that does not act on a HTTP Location header, and if sensible data is printed directly after an if statement like the above, the home-made client would receive it and by doing this circumvent your carefully constructed security measures.

01-29-2003, 01:23 AM
Thanks for the explanation mordred:)

But what's up with the closing curly brace? Does your comment mean don't do it?

And if so, why not? :D


01-29-2003, 10:54 AM
Hmh, my comment seems to add confusion instead of clearing it. What I meant was this:

// bad!
if ( !userIsAuthorized() ) {
header("Location: " . $loginPage);

compared to this:

// good!
if ( !userIsAuthorized() ) {
header("Location: " . $loginPage);
exit; // <- that's what's been missing in the bad example

01-29-2003, 08:26 PM
Thanks for the help Mordred, I have a new question that should be easy to answer...

I have 5 columns in my database...Title, Description, URL, Hits, and Notes.

Now when I do a:

This happens....

$row[0] is the title of the first site
$row[1] is the description of the first site
$row[2] is the URL of the first site.... :(

I'm a bit confused here, how do I call the title, description, and URL automatically as a 'set' without having to write out each one?

Would it be $row[$title], etc... or something???


EDIT: NEVERMIND, I figured it out, thanks:D

01-29-2003, 09:18 PM
Thanks to all you guys, the search functionality of my site actually works!:D

(Let the newbie have his moment)

Thanks for all the help, as soon as I figure out my above question, everything should be functional:)

01-29-2003, 10:25 PM
are we going to get a link?

01-29-2003, 11:19 PM
Sure Relyt,

It's at xick.com

I only have 3 sites in my database right now, so anything you search for will likely result in 0, but I'm planning on adding several more test sites to my db today (Including sites listed in my other thread:)

I need to get a new ISP i think, the site's running kind of slow:(

01-29-2003, 11:20 PM
Oops, also don't 'submit' any sites through my site, I haven't finished the submit box yet:D

01-30-2003, 09:30 AM
It doesn't find a thing... not even 'a'...?

01-30-2003, 03:39 PM
None of the site's have an 'a' in them, try 'i' or something :D

Like I said, I only have 3 sites in database right now:) All I gotta do now is figure out how to format the title, description, URL, etc.

01-30-2003, 04:57 PM
Ok I have a new problem..I'm trying to make a script that prevents users from searching for naughty stuff on my site.

This is what I tried:

$badwords= array("s--t", "f--k", etc, etc);

if ($SearchString==$badwords){
echo <<< EOF
Sorry, bad words are not allowed at this site, please search again!

Any advice? I think I screwed up the array, but I'm not sure where I went wrong.