Jump to content

[SOLVED] How to strip characters


peranha

Recommended Posts

How do you strip special characters from a username, password, other input.

 

here is the code that I currently have, but it doesnt strip ">

$username = empty($_POST['username']) ? die ("<b class=red>Enter A User Name</b>") : mysql_real_escape_string(strip_tags(htmlspecialchars($_POST['username'])));

 

You can register with ">name, and it will let you just fine.

Link to comment
Share on other sites

yes, i know what > is not a tag, but i was woundering how to get rid of a single instance, and how to get rid of " as well.

 

I tried your code, but it doesnt seem to work.

 

// Tags to strip for input.
$tags = array("<", ">");

// username to strip tags from.
$username = str_replace($tags, "", $_POST['username'] );

 

Here is what I input "> asdaf

 

Here is what I get from the output.

 

Here is the username you requested : \"> asdaf

 

Not sure where the \ is coming from either.

Link to comment
Share on other sites

You will have to post a bigger portion of your code as it is now. If you are using htmlspecialchars before the str_replace it won't work. Also it seems you are using addslashes.

To get rid of " you can add it to your array

 

$tags = array('<', '>','"');

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.