title: PHP case insensitive usermame match
body: <p><strong>ANSWER EDIT:</strong></p>
  
  <p>The fix was to change:
  <br><code>if (get_user_data( $input_user, $logindata ) === $input_pwd ) {</code> 
  <br>to<br>
  <code>if (get_user_data(strtolower($input_user), $logindata) === $input_pwd ) {</code> </p>
  
  <p>so that the username is forced to lowercase. I just have to be conscious to store my usernames as all lowercase too.
  <br></p>
  
  <p>I am aware of <code>strcasecmp</code>. I am not sure how that would apply to my working code though, as you can only compare 2 variables. </p>
  
  <p>Am I able to make <code>preg_match</code> case insensitive in the context of my working code below?
  Can I add the <code>/i</code> regex to my <code>preg_match</code> command to a returned variable?</p>
  
  <p>I just want the username that is entered by the user (including domain name) to be case insenstive. (ie. uSeRnAMe@dOmAIN1.CoM) without having to add every combination of valid username to my pseudo database!</p>
  
  <p><strong>This is my working code:</strong></p>
  
  <pre><code>// Get users
  $input_pwd = ( isset( $_POST["password"] ) ? $_POST["password"] : '' );
  $input_user = ( isset( $_POST["username"] ) ? $_POST["username"] : '' );
  
  // Your pseudo database here
  $usernames = array(
  "username@domain1.com",
  "username2@domain1.com",
  "username3@domain1.com",
  "username1@domain2.com", 
  "/[a-z][A-Z][0-9]@domain2\.com/",   // use an emtpy password string for each of these
  "/[^@]+@domain3\.com/"              // entries if they don't need to authenticate
  );
  
  $passwords = array( "password1", "password2", "password3", "password4", "", "" );
  
  // Create an array of username literals or patterns and corresponding redirection targets
  $targets = array(
  "username@domain1.com"           =&gt; "http://www.google.com",
  "username2@domain1.com"          =&gt; "http://www.yahoo.com",
  "username3@domain1.com"          =&gt; "http://www.stackoverflow.com",
  "username1@domain2.com"          =&gt; "http://www.serverfault.com",
  "/[a-z][A-Z][0-9]@domain2\.com/" =&gt; "http://target-for-aA1-usertypes.com",
  "/[^@]+@domain3\.com/"           =&gt; "http://target-for-all-domain3-users.com",
  "/.+/"                           =&gt; "http://default-target-if-all-else-fails.com",
  );
  
  $logindata = array_combine( $usernames, $passwords );
  
  if ( get_user_data( $input_user, $logindata ) === $input_pwd ) {
  
     session_start();
     $_SESSION["username"] = $input_user;
     header('Location: ' . get_user_data( $input_user, $targets ) );
     exit;
  
  } else {
  // Supplied username is invalid, or the corresponding password doesn't match
     header('Location: login.php?login_error=1'); 
     exit; 
  }
  
  function get_user_data ( $user, array $data ) {
  
      $retrieved = null;
  
      foreach ( $data as $user_pattern =&gt; $value ) {
  
          if (
                 ( $user_pattern[0] == '/' and preg_match( $user_pattern, $user ) )
              or ( $user_pattern[0] != '/' and $user_pattern === $user)
          ) {
              $retrieved = $value;
              break;
          }
      }
      return $retrieved;
  }
  </code></pre>