简体   繁体   English

PHP不区分大小写吗?

[英]Is PHP not case sensitive?

I am using MySQL and PHP . 我正在使用MySQLPHP In my database I have this table called users , and inside the users table have a record: 在我的数据库中,我有一个名为users表,在users表中有一条记录:

username: admin 用户名:admin

password: password 密码:密码

In my login page, I tried login as (password: password): 在我的登录页面中,我尝试登录为(密码:密码):

  • username : ADMIN -> result : can login 用户名:ADMIN - >结果:可以登录
  • username : admin -> result : can login 用户名:admin - >结果:可以登录

I store the username in my database as "admin", all lowercase. 我将用户名存储在我的数据库中,作为“admin”,全部小写。

In my PHP authentication page, I didn't include the strtolower() function. 在我的PHP身份验证页面中,我没有包含strtolower()函数。 Does it mean, in PHP the username form field that I submitted is not case sensitive? 这是不是意味着,在PHP中,我提交的用户名表单字段不区分大小写?

It's not PHP. 这不是PHP。 It's your database query that is not case sensitive. 这是您的数据库查询不区分大小写。

You can either make one of the operands binary string. 您可以将其中一个操作数作为二进制字符串。 For example: 例如:

SELECT 'abc' LIKE 'ABC';

This will return 1 or true . 这将返回1true While

SELECT 'abc' LIKE BINARY 'ABC';

will return 0 or false . 将返回0false

Yup, as Randell said, it's the database that is case-sensitive. 是的,正如Randell所说,这是一个区分大小写的数据库。 Check this article, for Can we make MySQL to be case sensitive for SELECT queries and can we force a column in MySQL to be always lowercase? 查看这篇文章, 我们可以让MySQL对SELECT查询区分大小写吗?我们可以强制MySQL中的列始终是小写的吗? .

I think have some way to go before it's clear... 我认为在明确之前还有一段路要走......

MySQL is NOT case sensitive for queries. MySQL对查询不区分大小写。 SELECT and select mean the same thing. SELECT和select意思相同。

The data in the tables is stored as is, but since you can only get information out with queries, you need to phrase them carefully. 表中的数据按原样存储,但由于您只能通过查询获取信息,因此需要仔细说明它们。

As Randell said 正如兰德尔所说

select 'abc' like 'ABC'

Will return TRUE (so will SELECT 'abc' like 'ABC' ) because LIKE ignores case differences 将返回TRUE(所以SELECT 'abc' like 'ABC' )因为LIKE忽略了大小写差异

select 'abc' like binary 'ABC'

will return FALSE (and so will SELECT 'abc' LIKE BINARY 'ABC' ) because LIKE BINARY looks more carefully. 将返回FALSE( SELECT 'abc' LIKE BINARY 'ABC'也是如此)因为LIKE BINARY看起来更仔细。 There IS a difference at the binary level. 二进制级别存在差异。

How should it know it's the username form field? 如何知道它是用户名表单字段?

If I remember right, in *nix a username was case-insensitive. 如果我没记错的话,在* nix中,用户名不区分大小写。 Are you using a library to store the userinformation and to compare it? 您是否使用库来存储用户信息并进行比较?

当您登录时,我认为您应该编写查询来验证用户名和密码在您保存的表中是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM