By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,619 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,619 IT Pros & Developers. It's quick & easy.

Need help, script to block certain images from certain sites

P: 5
Hey guys, I'm new here. Sorry if this is not the correct forum for my question.

I run a blog that gets a lot of comments from people. But often I have a problem with spammers that post images from those 3 sites I wish to block.

Is there a script I can use in the html that will block images/flash from certain domains.

Thanks a lot for any reply :)
Jan 17 '08 #1
Share this Question
Share on Google+
9 Replies


Markus
Expert 5K+
P: 6,050
I would probably us PHP as someone without javascript on would still be vulnerable to the images.

From php:

Use a regex to search the submitted comment for img tags then check where the image is located and if it matches one of the 'blacklisted' change it.

:)
Jan 17 '08 #2

P: 5
Thanks for your reply but I really suck at php... I just need a simple script that will prevent those images from those certain sites to show when a comment is submitted.

:)
Jan 17 '08 #3

Markus
Expert 5K+
P: 6,050
Something like this *should* do the trick:

[php]
<?php
$__imgLink = "img src=\"http://baddomain.com/some_file.jpg\"";
$_reg = '/baddomain.com/';
if(preg_match($_reg, $__imgLink)){
echo "bad image";
} else {
echo "good image";
}
?>
[/php]

Or does it have to be JS?
Jan 17 '08 #4

P: 5
Hey, thank you very much, I will try this and get back with result :)

Will this work with blocking flash from the domain too?
Jan 17 '08 #5

Markus
Expert 5K+
P: 6,050
Hey, thank you very much, I will try this and get back with result :)

Will this work with blocking flash from the domain too?
The theory is: you'll be checking the whole input which the user has submitted and if the baddomain is found (anywhere in the comment) you can just block the comment.
Jan 17 '08 #6

P: 5
Hey, sorry this seems to not work on my blog page. I haven't used php code on the page before maybe that's the problem, I have used JS and have some experience with it, sorry maybe I'm doing something wrong...
Jan 17 '08 #7

Markus
Expert 5K+
P: 6,050
Seeing as though i'm not you - might be possible in the near future - i don't know what you're doing.

Is your page a .php page?

Have you substituted $__imgLink with the user input that is submitted?

Maybe someone will come along with a javascript answer :)
Jan 17 '08 #8

P: 5
Yes, it's a php page. I dunno what I'm doing wrong but the images won't go away. Cleared cache and cookies, still there.

I have a couple of javascripts running on that same page, maybe there is conflicts of some sort I dunno. JS always works on the page.

Thanks anyway :)
Jan 17 '08 #9

Markus
Expert 5K+
P: 6,050
oh!
If the images are already there, this isn't going to stop them appearing!

It'd only snoop them out from new comments.

Can you not just delete the comments from your database?
Jan 17 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.