Is PHP case insensitive?

I use MySQL and PHP . In my database, I have a table with a name users, and inside the table usersthere is an entry:

username: admin

password: password

On my login page, I tried to log in as (password: password):

  • username: ADMIN → result: you can log in
  • username: admin → result: you can log in

I save the username in my database as "admin", all lowercase.

On my PHP authentication page, I did not enable the strtolower () function. Does this mean that in PHP the form field of the username I submitted is not case sensitive?

+5
source share
5 answers

This is not PHP. This is your database query that is not case sensitive.

You can either make one of the binary strings of the operands. For example:

SELECT 'abc' LIKE 'ABC';

This will return 1or true. While

SELECT 'abc' LIKE BINARY 'ABC';

will return 0or false.

+11
source

Yup, as Randell said, is a case-sensitive database. Check out this article, Can we make MySQL case-sensitive for SELECT queries, and can we make the MySQL column always be lowercase? .

+3
source

, - , ...

MySQL . SELECT select .

, , .

select 'abc' like 'ABC'

TRUE ( SELECT 'abc' like 'ABC'), LIKE

select 'abc' like binary 'ABC'

FALSE ( SELECT 'abc' LIKE BINARY 'ABC'), LIKE BINARY . .

+1
source

How should he know this username form field?

If I remember correctly, in * nix the username was case insensitive. Do you use a library to store user information and compare it?

0
source

When you log in, I think you should write a query to verify the username and password in the table you saved match.

-1
source

All Articles