PHP Clean Username  | 
	 
	 
For a list of all requirements and guidelines pertaining to posting a new Help topic, please click here.
This Month's Contests | Staff Member of the Month | Hosts Looking for Hostees | Hostees looking for Hosts | BigBookofResources
Submission Guidelines
PHP Clean Username  | 
	 
	 
			
			  Jul 3 2010, 12:29 AM
			
				 Post
					#1
					
				
			 
		 | 
	|
        	
				
					![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291  | 
       
			
			 
				Alas, another PHP topic. So, I have a login form. It works just like it should, but I realized I should allow clean usernames to be used. A clean username, basically, is an all-lowercase version of the original username (because some people are too lazy to use the shift key where necessary). So: 
			
			
					
		CODE <?php $username = $_POST['username']; $clean = strtolower($username); $password = $_POST['password']; $safe = md5($password); if (count($_POST) > 0) { if (!$username) $error = 'Please fill in your username'; else if (!$password) $error = 'Please fill in your password'; else if (!is_valid()) $error = 'It looks like you\'re not a valid user. Try checking your username or password or feel free to <a href="/register/">sign up</a>.'; else { $id = get_id(); setcookie('user', $username, time() + 31556926, '/'); setcookie('id', $id, 0, '/'); header($root . '/account/dashboard/'); } } else $error = ''; ?> is_valid() is in a functions file. I had it set so that it checked the username, password, and hashed password. However, I changed it around so that it'd check the clean username instead. CODE <?php function is_valid() { global $clean, $password, $safe; if (mysql_num_rows(mysql_query("SELECT ID FROM users WHERE clean_username = '$clean' AND password = '$password' AND safe_password = '$safe'")) > 0) return true; } ?> get_id() doesn't really do anything but get the ID from the MySQL database. Anyhow, what I can't understand is why it still generates an error. For example, let's say I have user named User. If I login using User, it works fine. However, if I use user, it generates an error. Now, I'd think that even if user is lowercase, $clean would just generate the same value (user). Aide?  | 
	
| 
			
			 | 
	|
 Mikeplyts   PHP Clean Username   Jul 3 2010, 12:29 AM
 
 fixtatik   I wouldn't think you need to have a "clea...   Jul 3 2010, 06:29 AM
 
 Mikeplyts   That was just a basic code of what I was using. I ...   Jul 3 2010, 02:27 PM
 
 Mikeplyts   QUOTE(Mikeplyts @ Jul 3 2010, 03:27 PM) T...   Jul 9 2010, 12:03 PM
 
 Uronacid   It looks fine to me. If all you're doing is ma...   Jul 9 2010, 09:02 AM![]() ![]()  |