note 46526 deleted from function.rawurlencode by sean
| From: | sean@php.net | Date: | Thu, 14 Oct 2004 14:07:56 +0000 |
| Subject: | note 46526 deleted from function.rawurlencode by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78541@lists.php.net to get a copy of this message | ||
Note Submitter: Jesse%3Cjesse%40codery.com%3E
----
Oftentimes when building a user system for a site you ask users for a username which must not
contain any spaces or punctuation. My reason for this, though it may not be the only reason, is so
that I can use their usernames in URLs such as: mysite.com/users/username. So when a user is
registering, rather than do a regex check for spaces and punctuation, I find it quicker and easier
to use urlencode().
if(urlencode($username) != $username)
echo "Your username may not contain spaces or punctuation";
If urlencode() changes the $username whatsoever, the condition will be met and the user will get the
error. Just a shortcut, but a surefire way to make sure a user's chosen name will be usable in
a URL later on. Like I said though, there may be other reasons, and characters that should be
accounted for.
----
Reason: bad code