homepage Welcome to WebmasterWorld Guest from 54.226.136.179
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

    
Does case ever matter in an email address
Problem for form handler
kiwibrit

10+ Year Member



 
Msg#: 3768339 posted 10:48 pm on Oct 17, 2008 (gmt 0)

I want to block all AOL email addresses being entered in a form. In php it's easy enough -

if (ereg("@aol\.com",$email)) {
header ('Location: http://www.example.com/toughmessage.htm');
}

works well at blocking lower case email addresses. But what about someone who uses upper case?

Well

$email = strtolower($email);
if (ereg("@aol\.com",$email)) {
header ('http://www.example.com/toughmessage.htm');
}

knocks that on the head. BUT. if I do a blanket change of all case to lower for all emails, would that ever cause problems for an email address that correctly had upper case letters in it - or in practice do all email handlers treat upper and lower case the same in email addresses?

[edited by: encyclo at 12:02 am (utc) on Oct. 18, 2008]
[edit reason] fixed formatting [/edit]

 

encyclo

WebmasterWorld Senior Member encyclo us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3768339 posted 12:11 am on Oct 18, 2008 (gmt 0)

The domain name is always case-insensitive, so you have no problem with the part after the @. The part before the @ is theoretically case-sensitive - however, in practice it virtually never is.

See RFC2821 [ietf.org]:
The local-part of a mailbox MUST BE treated as case sensitive. Therefore, SMTP implementations MUST take care to preserve the case of mailbox local-parts. Mailbox domains are not case sensitive. In particular, for some hosts the user "smith" is different from the user "Smith". However, exploiting the case sensitivity of mailbox local-parts impedes interoperability and is discouraged.

I think you will find that you will have no problem in switching the entire email address to lower-case, but if you want to be really careful, you could just change the domain name to lower-case.

kiwibrit

10+ Year Member



 
Msg#: 3768339 posted 7:02 am on Oct 18, 2008 (gmt 0)

Thanks encyclo.

kaled

WebmasterWorld Senior Member kaled us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3768339 posted 10:35 am on Oct 18, 2008 (gmt 0)

Surely you can perform a case-insensitive test. Failing this, simply copy the email address, convert it to lower case and test the copy. If it passes the test, use the original email address (with whatever case was supplied by the user).

Kaled.

kiwibrit

10+ Year Member



 
Msg#: 3768339 posted 10:07 pm on Oct 19, 2008 (gmt 0)

FWIW, ignoring checks for injections here, I went:

$email = $_POST['email'];
$email = strtolower($email);
if (ereg("@aol\.com",$email)) {
header ('http://www.example.com/toughmessage.htm');
exit;
}
else {
$email = $_POST['email'];
etc}

So more or less what you suggested.
Quckn'n'dirty - but it works.

Receptional Andy



 
Msg#: 3768339 posted 10:12 pm on Oct 19, 2008 (gmt 0)

You can remove the strtolower function entirely and instead use eregi [php.net] which is a case insensitive version of ereg (I prefer preg_match [php.net], myself, but no matter ;))

The only code you need is:

if (eregi("@aol\.com",$_POST['email'])) {
header ('http://www.example.com/toughmessage.htm');
exit;
}

Anything else should be handled by the rest of your script.

kiwibrit

10+ Year Member



 
Msg#: 3768339 posted 8:21 pm on Oct 20, 2008 (gmt 0)

Receptional Andy, much better - thanks.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved