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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -