Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Closed Thread
Blocking bad words in URL variable
Old 03-03-2010, 11:12 AM Blocking bad words in URL variable
Junior Talker

Posts: 5
Name: Lee
Trades: 0
I'm using a script that gets a variable from the url. Basically this is how search is implemented. I want to prevent pages with bad words in the url. example url ending /index.php?key=arse
I've been poking around after this line with mixed results.
Code:
variable.  $key = urlencode(custom_get('key'));
Not needing a perfect solution. Changing $key to something safe if it contains a word (ignore cap) from a bad word list.
jazzylee77 is offline
View Public Profile
 
 
Register now for full access!
Old 03-03-2010, 11:27 AM Re: Blocking bad words in URL variable
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
str_replace(); ?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
View Public Profile Visit lynxus's homepage!
 
Old 03-03-2010, 11:55 AM Re: Blocking bad words in URL variable
Junior Talker

Posts: 5
Name: Lee
Trades: 0
Quote:
Originally Posted by lynxus View Post
str_replace(); ?
That kinda works, but often just removing or replacing the bad word--will result in some nonsense search or worse. If the url ends with "having+***+with+a+dog" -- removing *** so it reads "having+with+a+dog" may likely return the same result. (YouTube video search)

I'd rather effectively say if $key contains any of the following badwords, then change to $key=sunshine
jazzylee77 is offline
View Public Profile
 
Old 03-03-2010, 12:01 PM Re: Blocking bad words in URL variable
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
http://us2.php.net/manual/en/function.stristr.php

PHP Code:
$badWords = array( /* ... */ );

foreach(
$badWords as $word)
{
     if(
stristr($key$word)) //if $key contains $word
     
{
           
$key 'sunshine';
     }

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
View Public Profile Visit NullPointer's homepage!
 
Old 03-03-2010, 12:16 PM Re: Blocking bad words in URL variable
Junior Talker

Posts: 5
Name: Lee
Trades: 0
Thanks NullPointer. That did it. I had been reading the page you linked to and others but it wasn't sinking in. It's been at least a year since I've dug into any PHP.
jazzylee77 is offline
View Public Profile
 
Closed Thread     « Reply to Blocking bad words in URL variable
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29246 seconds with 12 queries