Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8968491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:27:42+00:00 2026-06-15T17:27:42+00:00

ANSWER EDIT: The fix was to change: if (get_user_data( $input_user, $logindata ) === $input_pwd

  • 0

ANSWER EDIT:

The fix was to change:

if (get_user_data( $input_user, $logindata ) === $input_pwd ) {

to
if (get_user_data(strtolower($input_user), $logindata) === $input_pwd ) {

so that the username is forced to lowercase. I just have to be conscious to store my usernames as all lowercase too.

I am aware of strcasecmp. I am not sure how that would apply to my working code though, as you can only compare 2 variables.

Am I able to make preg_match case insensitive in the context of my working code below?
Can I add the /i regex to my preg_match command to a returned variable?

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!

This is my working 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"           => "http://www.google.com",
"username2@domain1.com"          => "http://www.yahoo.com",
"username3@domain1.com"          => "http://www.stackoverflow.com",
"username1@domain2.com"          => "http://www.serverfault.com",
"/[a-z][A-Z][0-9]@domain2\.com/" => "http://target-for-aA1-usertypes.com",
"/[^@]+@domain3\.com/"           => "http://target-for-all-domain3-users.com",
"/.+/"                           => "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 => $value ) {

        if (
               ( $user_pattern[0] == '/' and preg_match( $user_pattern, $user ) )
            or ( $user_pattern[0] != '/' and $user_pattern === $user)
        ) {
            $retrieved = $value;
            break;
        }
    }
    return $retrieved;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:27:43+00:00Added an answer on June 15, 2026 at 5:27 pm

    You can do a case insensitive match in PHP with i. For instance, the following will print ‘This matches!’:

    <?php
    if ( preg_match('/def/i', 'ABCDEF') ) {
        echo 'This matches!';
    }
    ?>
    

    So just add i to the pattern, and the case will be ignored.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: See my answer below--> I am wanting to have a view that when
FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
EDIT : Accepted answer points out what my issue was. I added another answer
[Edit] I've summarized the answer to the following below, the error lies in the
[EDIT] I am NOT accepting any answer which involves BigInteger, or other similarly inefficient
Edit: Building off of aL3xa's answer below, I've modified his syntax below. Not perfect,
EDIT 23-06-2012 10:24 (CET) : Found the answer Take a look at the bottom
EDIT: I figured it out from Bergi's answer in the end. Thanks Bergi. pubPrivExample
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.