Current location: Hot Scripts Forums » Programming Languages » PHP » Banned URL Array


Banned URL Array

Reply
  #1 (permalink)  
Old 04-13-04, 01:55 PM
optix's Avatar
optix optix is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Banned URL Array

OK what's a better way to do this?

I currently have a script where I store the array right there in the file like so..

$banned_url = array();
$banned_url[] = 'http://www.badsite.com';
$banned_url[] = 'http://www.badsite.com/';
$banned_url[] = 'http://badsite.com';
$banned_url[] = 'http://www.someothersite.pl/';
$banned_url[] = 'http://someothersite.pl';

I use that array to block bad URLs from being posted to my text file like this..

if (in_array("$url", $banned_url)) { echo "<br><br><font color=red><b>Banned Link<br>Nice try clown!<br><br></b></font>"; } else {


1) I'd like a better way to add banned URLs. I've made a script to let the admin enter a URL and add it to a text file one line at a time like $banned_url[] = '$url';. but is there a simpler way to use the array or even do it without an array?

2) You'll also notice I have to input every possible way you can write the URL. Is there a way to block the entire domain? I know there is I just don't know how.


Any help will be mucho appreciated.
__________________
[B] ModernConspiracy.com - Conspiracy Theory Forums (Talk Conspiracy)
DIYAutoForum.com - DIY Auto Forum
Reply With Quote
  #2 (permalink)  
Old 04-13-04, 02:18 PM
Frank Frank is offline
Newbie Coder
 
Join Date: Apr 2004
Location: Montreal, Canada
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
What I would think of would be to keep the URLs in an array and make a loop which would run every entry in the array and check it against the URL to see if it matches with preg_match and then run something with it to make it hide the banned site if it is actually a banned site or show the URL if it isn't.

Preg_match: http://www.php.net/preg_match


Frank
Reply With Quote
  #3 (permalink)  
Old 04-13-04, 02:46 PM
optix's Avatar
optix optix is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Sounds good but the problem with that is that I want something to alert the poster right off the bat that their link wasn't posted. Once I get this figured out I'll probably include a function that emails the script owner of the failed link attempt.
__________________
[B] ModernConspiracy.com - Conspiracy Theory Forums (Talk Conspiracy)
DIYAutoForum.com - DIY Auto Forum
Reply With Quote
  #4 (permalink)  
Old 04-14-04, 08:44 PM
optix's Avatar
optix optix is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
**bump** to the top
__________________
[B] ModernConspiracy.com - Conspiracy Theory Forums (Talk Conspiracy)
DIYAutoForum.com - DIY Auto Forum
Reply With Quote
  #5 (permalink)  
Old 04-14-04, 09:04 PM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by optix
Sounds good but the problem with that is that I want something to alert the poster right off the bat that their link wasn't posted. Once I get this figured out I'll probably include a function that emails the script owner of the failed link attempt.
Wait i don't exactally get what you mean....
you want it so that it alters the link in the post made if it includes a badurl?

EDIT:
PHP Code:

<?

$post 
'check it out lala.ca hmm weird name eh? how about sucks.net? or [url]http://lala.ca[/url] or [url]http://sucks.net[/url] but SUCKS.NET doesn't work..';

$bannedurl[] = '
/lala.ca/';
$bannedurl[] = '
/sucks.net/';

$goodurl = '
gfx-pro.ath.cx';

foreach($bannedurl as $url) {
 $post = preg_replace($url, $goodurl, $post);

}
echo $post;
?>
__________________
New beta project: GFX-PRO.ATH.CX
Description: GFX-PRO a great new project that anyone can and setup in less then a minute. [ More info ]
Website: http://gfx-pro.ath.cx
Status: Online
http://gfx-pro.ath.cx/sig.png

Last edited by Infinite_Hackers; 04-14-04 at 09:55 PM.
Reply With Quote
  #6 (permalink)  
Old 04-14-04, 09:41 PM
optix's Avatar
optix optix is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
No,

I just want it to recognize the bad url and not post it to the text file AND display a message.
__________________
[B] ModernConspiracy.com - Conspiracy Theory Forums (Talk Conspiracy)
DIYAutoForum.com - DIY Auto Forum
Reply With Quote
  #7 (permalink)  
Old 04-14-04, 10:18 PM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Edit.. ill get back to you in a sec( why can't i delete a post?!!? enable that )
__________________
New beta project: GFX-PRO.ATH.CX
Description: GFX-PRO a great new project that anyone can and setup in less then a minute. [ More info ]
Website: http://gfx-pro.ath.cx
Status: Online
http://gfx-pro.ath.cx/sig.png

Last edited by Infinite_Hackers; 04-14-04 at 10:21 PM.
Reply With Quote
  #8 (permalink)  
Old 04-15-04, 07:38 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
first, you don't really need to have this line:
$banned_url = array();

just $banned_url[] is fine and will inetilize the array ..

and there is no need to use regexp function here !! it's only string replacement !!
so just use str_replace();
if you want to alert use a small IF statment !!
PHP Code:

$banned_url[] = 'http://www.badsite.com/';

$banned_url[] = 'http://badsite.com';
$banned_url[] = 'http://www.someothersite.pl/';
$banned_url[] = 'http://someothersite.pl';

//the text message ..
$text trim(addslashes($_POST['text']));

foreach (
$banned_url as $nogood) {
  if (
stristr($text$nogood)) {
    
$alert[] = $nogood;
    
$text str_replace($nogood'<i>Bad URL!</i>'$text);
  }
}

if (
count($alert) > 0) {
  foreach(
$alert as $promp) {
      
$error .= 'You tried to use this URL '.$promp.' but it is a bad URL !';
  }
}

//echo $error where ever you want .. 
this will replace all bad URLs (if found) with an Italic "Bad URL" !!
then if the array alert has any elemnts, then we bump it into $error var ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #9 (permalink)  
Old 04-15-04, 08:17 AM
optix's Avatar
optix optix is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Hey thanks alot.

What about banning multiple entire domains instead of having to add a URL for every minor change like http://mydomain.com or http://mydomain.com/porn and http://mydomain.com/ with the traling slash etc.

Thanks,

George
__________________
[B] ModernConspiracy.com - Conspiracy Theory Forums (Talk Conspiracy)
DIYAutoForum.com - DIY Auto Forum
Reply With Quote
  #10 (permalink)  
Old 04-15-04, 08:39 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I wont say anything until you try the code I wrote and try all these URLs and see how it will work
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multidimensional Array Sorting Kage PHP 6 12-12-05 04:19 PM
How do I write an array to a file? bark PHP 2 03-30-04 12:28 PM
linking to iframe not working :( j0d JavaScript 5 01-19-04 08:14 PM
looking for a banned words list cath Script Requests 6 10-29-03 06:18 PM
asp: values in array not in order?? seala ASP 0 08-16-03 12:06 PM


All times are GMT -5. The time now is 10:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.