Upper and lower case in PHP

Asked

Viewed 997 times

-3

I’m having a somewhat unusual (or common I don’t know) problem. I have an e-mail registration field. The user adds an email, the system checks if the email already exists in the database, if not he registers, if yes, he does not register.

It turns out that if the user differentiates a letter from the email to uppercase the system interprets the email differently. For example, there is an email in the BD: "[email protected]", if a user tries to register the email "[email protected]" the system allows.

What can I do to disable this uppercase/lowercase check? Or is it not necessary? the system has to do this check anyway.

  • Considerations you should do: If I send the email to X will be the same as I send to x? If yes, you must treat to consider them equivalent. Another is: it will matter to the user to register X and store in the bank x?

  • Have you read RFC to know which parts make a difference? Depending on the Marcos@ server and milestones may actually be different accounts. at (@) the normal rules apply to Domain name. on the left, the implementation is allowed to do as it sees fit.

  • But that wouldn’t be half wrong, because, like, if I’m a public person who gets a lot of emails at the [email protected]. If the guy types the email on his cell phone he already leaves the first letter capitalized, so [email protected], so the emails that were for me are addressed to another, I think there is no e-mail server that allows it to know.

  • It is better to develop in certainty than in speculation... quantity of bugs certainly decreases.

2 answers

1

The easiest way would be in the INSERT treat all the strings you use for comparisons (in PHP, because in the database, depending on which one you use is not case sensitive).


Complementing what Lucas said, the easiest ways would be:

strtolower(): converts a string to lowercase

Example:

$str = "[email protected]";
$str = strtolower($str);
echo $str; // Resultado: [email protected]

strtoupper(): converts a string to capital letters:

Example:

$str = "[email protected]";
$str = strtoupper($str);
echo $str; // Resultado: [email protected]
  • Thank you. Even before your answers I had already researched and solved the problem, but thanks a lot!!!

0

You can use the strtolower() function to convert the entire string to lower case and query the database with return of that function.

$email = strtolower($email);

  • Thank you. Even before your answers I had already researched and solved the problem, but thanks a lot!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.