Jump to content

URL bbcode safe?


phpmo

Recommended Posts

Here is what I'm doing.

 

The enter link.com that gets placed into $message

 

So I do:

 

Before it is added the the DB.

$_POST[message] = htmlspecialchars($_POST[message]);

 

Then when showing the DB field I run it through this to get my link and html.

$message = preg_replace ('/\[url\](.*?)\[\/url\]/is','<a href="$1">$1</a>', $message);

 

Any problems with this method?

Link to comment
https://forums.phpfreaks.com/topic/182028-url-bbcode-safe/
Share on other sites

Personally I tend to use htmlentities as opposed to htmlspecialchars, I also sometimes call strip_tags first, but that's just to get rid of it rather than having the XSS strings appear in posts as sanitised code. To my knowledge that should be good enough to prevent any XSS. Preventing SQL injection is a seperate issue which should also be addressed. While I'm at it I'll point out your code isn't really correct, you are using constants rather than strings for key values. This will actually be throwing notices, it's just PHP is clever enough to work out what you meant. You should access associative arrays using string values for the key like so....

 

$_POST['message'] = htmlspecialchars($_POST['message']);

Link to comment
https://forums.phpfreaks.com/topic/182028-url-bbcode-safe/#findComment-960245
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.