Crew-Portal Posted August 20, 2007 Share Posted August 20, 2007 Hi I have a fully functional PHP / MySQL Script with Inserts Like $_POST['username'] and $_POST['password'] Now the scripts are set up so if NULL < or > Max Charactors It Displays Errors And So Forth... The only bad thing is they can user HTML in thier username to make thier name bold. How do i prevent certain charactors to be used in registration? Please help a N00B. Thanx in advance i am goin to bed so I will not thank you till tommorrow! So dont rush yourselves. Cya, in the morning! Quote Link to comment https://forums.phpfreaks.com/topic/65769-solved-filter-bad-charactors/ Share on other sites More sharing options...
btherl Posted August 20, 2007 Share Posted August 20, 2007 One approach is to specify what is allowed, rather than what is not allowed: $username = preg_replace('|[^[:alnum:]]|', '', $username); This will remove anything that is not "alnum", which includes a-z, A-Z and 0-9 only. Another option is to escape your usernames before output. In this case, any attempts to use html will result in the html displaying as source, and not being interpreted: print htmlspecialchars($username); From the manual for this function: "This function is useful in preventing user-supplied text from containing HTML markup, such as in a message board or guest book application." Quote Link to comment https://forums.phpfreaks.com/topic/65769-solved-filter-bad-charactors/#findComment-328614 Share on other sites More sharing options...
tibberous Posted August 20, 2007 Share Posted August 20, 2007 Use strip_tags. $username = strip_tags($_POST['username']); Quote Link to comment https://forums.phpfreaks.com/topic/65769-solved-filter-bad-charactors/#findComment-328630 Share on other sites More sharing options...
Crew-Portal Posted August 20, 2007 Author Share Posted August 20, 2007 K I am awake now and thank you for the posts! TOPIC SOLVED!!! Quote Link to comment https://forums.phpfreaks.com/topic/65769-solved-filter-bad-charactors/#findComment-328832 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.