Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Check Domain -> Email Address

Quote Reply
Check Domain -> Email Address
Okay...I've added this small code hack into my signup account script(powered by Links v.1.13:

In Reply To:

if ($email) {
if ($email !~ /.+\@.+\..+/) {
$email_error .= "$CUSTOM{warn_img} The format of your <span class=\"boldredtext\">email address</span> is incorrect.
";
}
else {
($account,$domain) = (split /\@/, $email);
$checkdomain = qq|http://$domain|;
$CUSTOM{ua} = new LWP::UserAgent;
$CUSTOM{ua}->agent("UrlScope/8.0");
$CUSTOM{ua}->timeout(30); # in seconds
$CUSTOM{req} = new HTTP::Request 'GET' => ($checkdomain);
$CUSTOM{res} = $CUSTOM{ua}->request($CUSTOM{req});
if ($CUSTOM{res}->is_error) {
$email_error .= "$CUSTOM{warn_img} The email address you submitted is not active or no longer in service. Please select another email address.
";

}
}
}


BTW: $email is defined above in the sub as my $email = $in->param('Email');.

And later on in the sub, I have the following error check codes:

Code:

if (($country_error) or ($contact_error) or ($email_error) or ($eperm_error) or ($userperm_error) or ($sendemailperm_error) or ($newsperm_error) or ($username_error) or ($pword_error) or ($pword2_error)) {
my $title_linked = &build_linked_members_title ("Register Account/Error: Unable to Process Form");
&site_html_signup_form ( {error => "The following errors occurred when you tried to fill out this form.", country_error => $country_error, contact_error => $contact_error, email_error => $email_error, eperm_error => $eperm_error, userperm_error => $userperm_error, sendemailperm_error => $sendemailperm_error, newsperm_error => $newsperm_error, username_error => $username_error, pword_error => $pword_error, pword2_error => $pword2_error, username => $username, author => $author, password => $password, password2 => $password2, email => $email, email_permission => $email_permission, username_permission => $username_permission, send_permission => $send_permission, newsletter_permission => $newsletter_permission, country => $country_select, state => $state_select, city => $city, address => $address, zipcode => $zipcode, telephone => $telephone, fax => $fax, hobbies => $hobbies, research_interests => $resint, signature => $signature, title_linked => $title_linked}, $dynamic );
return;
}
else {
my $title_linked = &build_linked_members_title ("Register Account/Confirmation Screen");
&site_html_signup_confirm ( {username => $username, author => $author, password => $password, email => $email, email_permission => $email_perm, username_permission => $user_perm, send_permission => $send_perm, Country => $country, State => $state, city => $city, address => $address, zipcode => $zipcode, telephone => $telephone, fax => $fax, hobbies => $hobbies, research_interests => $resint, signature => $signature, newsletter_permission => $news_perm, title_linked => $title_linked}, $in, $dynamic );
return;
}


Notice the bolded codes above...

The code hack works for the most part...it will only allow "
active" domains to be entered in the Email field. However, the error message that appears is the following:

Code:

Content-type: text/html

Software error:

DBSQL (25342): Fatal Error: Unable to load the DBI module: 'Can't connect to fkladfnlkdf.com:80 (Bad hostname 'fkladfnlkdf.com')' at /mnt/web/guide/anthrotech/members/bin/signup.cgi line 265

For help, please send mail to the webmaster (Webmaster), giving this error message and the time and date of the error.


Line 265 is the following:

Code:

my $user_r = $USERDB->get_user_record ($username, 'HASH');


BTW: I've added another sub in the DBSQL file that gets records based on Username than the PRIMARY KEY, which is UserID....

If anyone sees something I am missing, please let me know.

Thanks in advance.

Regards,

Eliot Lee
Quote Reply
Re: Check Domain -> Email Address In reply to
Just a couple of things I noticed are what happens if $email isn't defined because accoring to that code if $email is defined then the code will run, otherwise nothing will happen. Don't you need the extra else { at the bottom to go with the first if ($email) {

So like:
Code:
if ($email) {
do all that stuff
} else {
there is no email so do something else
}
You could even get rid of if ($email) { altogether as the regex checks it is valid so you don't need if ($email) { as well.

Anyway as far as the errors goes, surely that is correct as 'fkladfnlkdf.com' isn't a valid domain so the error is being reported correctly.

Edit: Did I misunderstand what you were asking?

Installs:http://wiredon.net/gt
FAQ:http://www.perlmad.com

Quote Reply
Re: Check Domain -> Email Address In reply to
Paul,

Thanks for the response.

1) I already have codes that checks for null values in the $email field, which I did not post:

if (!$email) {
$email_error .= "Error Message.";
}

2) Yes, you are missing my point, which is that what I would like to happen is that if the domain is not active, it will go to the formatted error page, (look at the $email_error codes), and NOT the CGI Fatal Errors page.

Does that make sense?

Thanks again for your reply. I appreciate it.

Regards,

Eliot Lee