Jump to content

[SOLVED] Filter Bad Charactors


Crew-Portal

Recommended Posts

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!

Link to comment
Share on other sites

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."

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.