Grego Posted June 18, 2007 Share Posted June 18, 2007 I've got textareas for my users to input descriptions etc into. The problem is that when they enter HTML or PHP code, it comes out like that, which means they could potentially access the database and mess around with the page. How can I keep my pages secure when displaying this text. IE: How can I make it actually say on screen: "Hello, I'm <strong>Grego</strong>" rather than "Hello, I'm Grego"? Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/ Share on other sites More sharing options...
chocopi Posted June 18, 2007 Share Posted June 18, 2007 You could use striptags: <?php $text = "Hello <strong>Grego</strong>"; echo $text; echo strip_tags($text); ?> Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/#findComment-276643 Share on other sites More sharing options...
Grego Posted June 18, 2007 Author Share Posted June 18, 2007 Oh that's a handy function Thanks Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/#findComment-276648 Share on other sites More sharing options...
chocopi Posted June 18, 2007 Share Posted June 18, 2007 However, that will only stop html tags it wont stop the likes of mysql stuff Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/#findComment-276650 Share on other sites More sharing options...
Grego Posted June 18, 2007 Author Share Posted June 18, 2007 So if someone put in <? mysql_connect ?>, it would work? (if it has the correct syntax and arguments) Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/#findComment-276651 Share on other sites More sharing options...
chocopi Posted June 18, 2007 Share Posted June 18, 2007 Well i think they could use stuff like SELECT FROM or DELETE FROM in my code i use this on submit <?php $original = $_POST['message']; $original = strip_tags($original); $original = htmlentities($original, ENT_QUOTES); ?> and then to get it back <?php $text = $_POST['original']; $text = mysql_real_escape_string($text); $text = stripslashes($text); ?> That might cause some problems, but it should be fine ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/#findComment-276655 Share on other sites More sharing options...
Grego Posted June 18, 2007 Author Share Posted June 18, 2007 Could you just shrink that all down to: $original=htmlentities(strip_tags($_POST['message']), ENT_QUOTES); Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/#findComment-276658 Share on other sites More sharing options...
chocopi Posted June 18, 2007 Share Posted June 18, 2007 yea you can, but i just prefer being able to see whats going on step by step, especially as i had to keep swapping stuff around Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/#findComment-276660 Share on other sites More sharing options...
Grego Posted June 18, 2007 Author Share Posted June 18, 2007 The strip_tags function is removing all the <? ?> references. So I think I'm safe just to use that. Quote Link to comment https://forums.phpfreaks.com/topic/56015-solved-keeping-your-site-secure-from-users/#findComment-276663 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.