View Full Version : Search
alexjewell
05-19-2006, 03:48 PM
I'm going to need a search script pretty soon for a client.
He's a dropshipper and wants his items searchable.
My issue is I don't know how to do this.
I'm a little new to PHP and with every answer I get on here, I learn a lot.
Any ideas as to how to go about this?
Maybe something like, if they search for this, display this code. Then, if they search for this, display this code...
Or something along those lines?
Simple and easy?
Thanks
Use a database. That's what they're for.
cybercoder
05-20-2006, 04:36 PM
No, you could also use flat file, but a database is more secure.
mwinter
05-20-2006, 05:27 PM
No, you could also use flat file, but a database is more secure.A flat file is no less secure, but a database will do all of the leg work for you. Why write code to search through a formatted file instead of using a SELECT SQL statement, which will have pattern matching and regular expressions built-in (though the latter may depend on the DBMS in use)?
Mike
cybercoder
05-21-2006, 11:48 AM
Flat file are dependant on text files, and txt files only have a chmod protecting them. On the otherhand, a database has a password and username authentication running from a specific server address.
Rubbish. Where do you think databases store their data? In a file.
In fact, if anything, a plain-text file is more secure, because databases generally allow TCP connections.
"Only" a chmod? I don't know about Windows permissions, but on *n?x that's usually quite sufficient to keep a system secure, unless the attacker has local access.
mwinter
05-21-2006, 08:02 PM
Flat file are dependant on text files, and txt files only have a chmod protecting them.If the file system doesn't give a user permission to read or modify the file, then they won't be able to modify it. Simple enough, yes? Furthermore, if the server is given permission to read or modify the file, but configured not to allow remote access[1], then said file can be used by a script, but never directly accessed.
On the otherhand, a database has a password and username authentication running from a specific server address.Databases are far from invulnerable. It's all a matter of configuration; good administration can render a file unreadable to third parties, just as bad administration or programming can leave a database wide open. Neither one is inherently better than the other.
I don't know about Windows permissions, but on *n?x that's usually quite sufficient to keep a system secure, unless the attacker has local access.The only way to access the data and configuration files for MySQL and PostgreSQL here is to log in as the administrator. Both DBMS run under their own, separate accounts (for which both local and remote login is forbidden), and only an administrator is able to traverse into those directories. Finally, database administration is restricted by IP address, and only one user account has full control of the database.
Secure? I think so. :)
Mike
[1] The use of access controls can be used to effect this protection. Alternatively, the file can be placed outside the DOCUMENT_ROOT directory.
djr33
05-21-2006, 08:02 PM
It's a fairly complex thing to do, depending on complexity.
You need to interpret the input into keywords (seperate at spaces), or not... just search the exact phrase, but that will limit results, obviously.
Then you need to have a matching set of keywords for each possible result. Or have the actual result (text, a list, whatever) act as those keywords.
Then you need to find which ones match.
Then you need to display the matching results.
Overall, it's fairly complex.
Select statements would work fine, but not if you want anything beyond direct matching between things. If someone searched for "php html" for example and the item in the database was "php" it would not be a match, unless you did some more complex stuff to the input.
Likewise, "php" would not match "php html" if that was an item. You'd need to seperate those as well.
Gotta figure out a strategy, then get into coding it.
The only way to access the data and configuration files for MySQL and PostgreSQL here is to log in as the administrator.True that. I was just pointing out that databases relied on filesystem permissions too :)
Select statements would work fine, but not if you want anything beyond direct matching between things. If someone searched for "php html" for example and the item in the database was "php" it would not be a match, unless you did some more complex stuff to the input.
Likewise, "php" would not match "php html" if that was an item. You'd need to seperate those as well.Or unless you used LIKE '%php%' or even REGEXP '\bphp\b'.
Hol˙Cow
05-22-2006, 11:47 AM
U can use this simple script.
Installation is along with it
http://rapidshare.de/files/21088947/search.zip.html
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.