PDA

View Full Version : regex help regarding img tags


Jenta
05-05-2005, 12:30 AM
to prevent hotlinking to unauthorized domains im trying to limit the img tag to only a couple
mysite.com and somefreeimagesite.com

functions_bbcodeparse.php, you have this

// do https://vborg.vbsupport.ru/
$bbcode = preg_replace('#\[img\]\s*(https?://([^<>*"' . iif(!$vboptions['allowdynimg'], '?&') . ']+|[a-z0-9/\\._\- !]+))\[/img\]#iUe', "handle_bbcode_img_match('\\1')", $bbcode);


i have modified it to this and it makes it so only mysite.com will work
(added www.mysite.com after the http:// part )

// do https://vborg.vbsupport.ru/
$bbcode = preg_replace('#\\s*(http://www.mysite.com([^<>*"' . iif(!$vboptions['allowdynimg'], '?&') . ']+|[a-z0-9/\\._\- !]+))\[/img\]#iUe', "handle_bbcode_img_match('\\1')", $bbcode);

how would i go about adding an additional domain?
the urls from the 2nd domain are in this format: http://img(somenumbers and other stuff).cx
just making it work with http://img will be fine if thats all that can be done

ideally, i would like for it to jumble up anything posted that does not fit the two formats
like if someone does [img]http://google.com/image.type it will not parse it but will also replace it with some random characters like
hqroiqrq9212o424229uy92r2252

sabret00the
05-05-2005, 07:03 PM
wouldn't it be easier to use .htaccess to do this?

Jenta
05-06-2005, 08:06 AM
not sure what u mean
.htaccess only stops hotlinking on my domain, not google's, cnn's, etc
unless i am missing something
can u explain?
thanks

sabret00the
05-06-2005, 10:24 AM
hold on, you're NOT trying to stop people hotlinking your images, but rather stop your site from hotlinking to other sites images?

Jenta
05-06-2005, 01:02 PM
right
other domains

to prevent hotlinking to unauthorized domains im trying to limit the img tag to only a couple
mysite.com and somefreeimagesite.com


so if they type some other domain functions_bbcodeparse.php
will jumble things up

i think i see where to do it but any help would be appreciated
its a bit below $bbcode = preg_replace that it actually starts outputting whats shown in the post

btw, i got the first part working by just duplicating that line with the 2nd domain
so i now have 2 $bbcode = preg_replace..... lines one above the other and it works but ????

i was reading for a day trying things and it said the | character is like a either or but when i tried the regex on the single line it did not work
domain1|domain2...rest of line

so now i have to lines with the only diff being domain 1 and domain 2
but its still will allow anything that starts with http://img
would rather it match the http://img (somthing here) .cx

Ratchet
06-24-2005, 03:38 PM
We had a problem with this awhile ago with people posting links to innapropriate material. The easiest solution we found was to simply add the domain to the censor list, that way anytime someone tries to post a link to a bad site it just comes out as, for example, http://www.********.com.