Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Check URLs and restrict user entering free email address

Posted on 2008-10-26
4
Medium Priority
?
288 Views
Last Modified: 2008-12-08
I have a free evaluation form that I want people to use, but I would like it to do two checks before sending the form:
1. Check the URLs entered are real websites
2. If a user enters a free email (hotmail, yahoo etc.) address, I would like to show an error message, asking them to use another address.
Thanks,
Mike
0
Comment
Question by:mikejc28
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 600 total points
ID: 22810408
$bad_emails = array('hotmail.com', 'yahoo.com', 'gmail.com', 'email.com', 'aim.com');
$the_email = 'ned@gmail.com';

$bad = false;
foreach($bad_emails as $domain)
 if(strstr($the_email, $domain))
  $bad = true

if($bad)
{
echo 'Please get a real email address';
}

As far as check whether a website is valid or not, you would need to probably check to see if it has any DNS records associated with it, or, you can just curl to it and see if anything comes back...

Brian
0
 
LVL 14

Assisted Solution

by:EMB01
EMB01 earned 600 total points
ID: 22812019
Here's a code to check if a website is real and exists:
<?
function url_exists($strURL) {
    $resURL = curl_init();
    curl_setopt($resURL, CURLOPT_URL, $strURL);
    curl_setopt($resURL, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($resURL, CURLOPT_HEADERFUNCTION, 'curlHeaderCallback');
    curl_setopt($resURL, CURLOPT_FAILONERROR, 1);

    curl_exec ($resURL);

    $intReturnCode = curl_getinfo($resURL, CURLINFO_HTTP_CODE);
    curl_close ($resURL);

    if ($intReturnCode != 200 && $intReturnCode != 302 && $intReturnCode != 304) {
       return false;
    }Else{
        return true ;
    }
}

//Usage Example :
If(url_exists("http://www.weberdev.com/addexample.php3")) {
    Echo"URL Exists";
}Else{
    Echo"URL doesnot exist";
}
?>

Source: http://www.weberdev.com/get_example-4335.html
0
 

Author Comment

by:mikejc28
ID: 22818639
Thanks BrianGEFF719.
Question: How do I code this into my form to check the email entered?
<form method="POST" action="http://www.wolf21.com/analysis.php">
<p>Your website address:
<input name="yourwebsite" type="text" value="http://www." size="30">
</p>
<p>1st competitors website:<br />
<input name="competitor1website" type="text" value="http://www." size="30">
</p>
<p>2nd competitors website:<br />
<input name="competitor2website" type="text" value="http://www." size="30">
</p>
<p>Key phrase:<br />
<input name="keyphrase" type="text" value="eg. marketing company toronto" size="30">
</p>
<p>Your email address:<br />
<input name="EmailFrom" type="text" size="30">
</p>
<p>We will email you a FREE report comparing you and your top two competitors. No strings attached.</p>
<br/><input type="submit" name="submit" value="Submit">
</form>

Open in new window

0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 300 total points
ID: 22821921
You would add the analysis code to the action script: http://www.wolf21.com/analysis.php

If you post that script as it sits today, we may be able to help you get the mods made.  Something like the code snippet...

Note that you could let the check_valid_email() function to disallow these free email addresses, however there are lots of perfectly legit people out there who use GMail - that's an application design question.

Good luck with your project, ~Ray
<?php // http://www.wolf21.com/analysis.php
 
// GET THE EMAIL ARGUMENT
$eml = $_POST["EmailFrom"];
 
// TEST THE EMAIL ARGUMENT
if (!check_valid_email($eml)) { /* EMAIL IS NOT USABLE */ }
 
// FUNCTION TO TEST THE QUALITY OF AN EMAIL ADDRESS
function check_valid_email($email) {
    $bad_emails = array('yahoo.com', 'hotmail.com', 'gmail.com', 'etc...');
    $email  = trim(strtolower($email));
    if (!eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $email)) return FALSE;
    if (strpos($email, '@')) {
        $emaila = explode('@', $email);
        if (in_array($emaila[1], $bad_emails)) return FALSE;
        if     ($emaila[0] == '') return FALSE;
        elseif ($emaila[1] == '') return FALSE;
        elseif ((checkdnsrr($emaila[1],"MX") || checkdnsrr($emaila[1],"A"))) return TRUE;
        else   return FALSE;
    } else return FALSE;
}

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question