php - HTML Form Case Sensitive -
this might rather weird question, when log in webpage, works, if write in capitals. anyway, i've made "kill" function on page (role playing game can kill others). , i've tried make simple function make unable kill yourself. here code:
if ("$killuser"=="$user") { echo "you can't kill yourself!"; }
$user = current user logged in, trying use function
$killuser = input in html form (the user trying kill)
the problem is, if username "user", , attempt kill "user", says can't kill myself, if write in capitals, or not it's stored in database, won't, , i'll able kill myself. way, username table in database varchar , collation utf8_general_ci.
convert both variables lower-case , compare it:
if ( strtolower($killuser) == strtolower($user)) { echo "you can't kill yourself!"; }
alternatively, use strcasecmp()
:
if (strcasecmp($killuser, $user) == 0) { echo "you can't kill yourself!"; }
Comments
Post a Comment