Latest: buggy behaviour of parent:: in PHP 5.3.3

Content with Style

Web Technique

fulltext & weighted relevance

by Pascal Opitz on January 9 2007, 09:14

Via JV Multimedia:

A quick and neat way to use MySQL fulltext search with weighted relevance modificators.



SELECT
*,
(MATCH (category) AGAINST ('$query' IN BOOLEAN MODE)*100) +
(MATCH (title) AGAINST ('$query' IN BOOLEAN MODE)*10) +
MATCH (body) AGAINST ('$query' IN BOOLEAN MODE) AS rating
FROM
stories
WHERE
MATCH (title,category,body) AGAINST ('$query' IN BOOLEAN MODE)
ORDER BY
rating DESC
LIMIT 0,10

http://www.jvmultimedia.com/portal/node/61

Comments

  • Extremely! Insecure!
    Never! Ever! pass in $query just like that. Its the #1 security hole in most systems. It is called SQL injection.

    by Bèr Kessels on January 15 2007, 04:52 - #

  • Ber, first of all thank you for bringing this up. I can see why you are concerned, even though I don’t think you have a point here. Let me explain to you why:

    By default register_globals is off, and I always have turned it off. Which means that $query in the example above cannot refer to the equivalent of $_GET[‘query’].

    That means that $query is just any variable. SURELY IT SHOULD BE ESCAPED FIRST! But you cannot really tell if that hasn’t happened by just looking at the example above.

    If you were thinking that this refers to a GET variable because you are still working with register_globals turned on, then I strongly advise you to not do so anymore, because that would mean a major security hole.

    by Pascal Opitz on January 15 2007, 07:05 - #

Leave your comment

Comments are moderated.
Tags allowed: a, strong, em, code, ul, ol, li, q, blockquote, br, p

Advertisement
Advertisement