SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Search...

  1. #1
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Search...

    I have a search field which inserts data into a mysql table.

    If someone inserts for example, a URL in the search box, it still inserts it into the table.

    Its all secure, I just want it to insert text only.

    For example:

    search.php?q=this+is+a+search

    Insert that ^

    and not search.php?q=http://www.thisisnotasearch.com/lol.html

    What can I do to eliminate URLs being inserted?
    :-)

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Check if the text contains http:// perhaps?

    PHP Code:
    if (strpos($_GET['q'], 'http://') === false) {
      
    //save the query

    You can't really say "I only want text", because URLs are text.

  3. #3
    SitePoint Addict Latox's Avatar
    Join Date
    Dec 2008
    Location
    Australia
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can't you check the whole URL, see if http://, www., .com are present, if are return false?
    :-)

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    http:// dangrossman.info does not have a "www." or ".com", but it's a URL

    Would someone ever type "http://" in your search box and it NOT be a URL?

    But sure, you can write a regular expression which matches URLs, and use preg_match


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •