1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Domain Validation question

Discussion in 'PHP' started by Hecky, Jan 23, 2010.

  1. #1
    Hi,

    If I have a list of domains being submitted to a php script in one big string, how can I make sure that they're all proper domains ( I'll define the acceptable extensions ), put them into different array slots, and also format them into 'name.extension'?

    Any help would be appreciated :)
     
    Hecky, Jan 23, 2010 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    parse_url() ?
    then just use a regex to validate the extensions
     
    JAY6390, Jan 23, 2010 IP
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Also for splitting them into an array you'll want to use explode() and then a foreach loop to loop through the list of values
     
    JAY6390, Jan 23, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    danx10, Jan 23, 2010 IP
  5. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The problem with the filter_var is that it allows email addresses such as
    username@1 which isnt exactly the kind of email you want
     
    JAY6390, Jan 24, 2010 IP
  6. Hecky

    Hecky Like a Dungeon Dragon!

    Messages:
    5,656
    Likes Received:
    284
    Best Answers:
    1
    Trophy Points:
    0
    #6
    Thanks guys for your help, I meant submitting domains not email addresses :)
     
    Hecky, Jan 24, 2010 IP
  7. K.Meier

    K.Meier Well-Known Member

    Messages:
    281
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    110
    #7
    What do you mean by proper domains? Do you also want to check if they are actually used? Or do you just want to make sure that it could be a Domain. So anything like "asdsdadadsqqqqqxcaa1293.com" would be acceptable?
     
    K.Meier, Jan 24, 2010 IP
  8. Hecky

    Hecky Like a Dungeon Dragon!

    Messages:
    5,656
    Likes Received:
    284
    Best Answers:
    1
    Trophy Points:
    0
    #8
    Hecky, Jan 24, 2010 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    Maybe, but I meant the following:

    FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED
    Code (markup):
    :p
     
    danx10, Jan 24, 2010 IP
  10. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #10
    Follow this example:

    <?php
      $domain = "http://google.com";
      //check if domains valid
      if (!filter_var($domain, FILTER_VALIDATE_URL)){
          echo "Invalid URL";
      } else {
          //format domain to look like "domain.extension";
          $domain = parse_url($domain);
          echo "Valid URL";
          echo $domain['host'];
      }
    ?>
    PHP:
     
    danx10, Jan 24, 2010 IP
  11. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #11
    FILTER_VALIDATE_URL will validate the following...
    http://-/
    http://1/
    So it's not all that reliable either, plus you would want to validate it before using parse_url
     
    JAY6390, Jan 24, 2010 IP
    Hecky likes this.
  12. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #12
    In that case, here's a better method:

    <?php
    $domains = array("http://google.com", "http://www.google.com", "http://google.com", "chipdcnv.com");
    
    foreach ($domains as $domain){
    if(!getmxrr($domain, $MXHost)){
    $host = parse_url($domain);
    echo $host['host']." <br>";
    }
    }
    ?>
    PHP:
     
    danx10, Jan 24, 2010 IP
    Hecky likes this.
  13. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #13
    ...not all hosts will return the mx record lol...The best method is still to use a regex IMO
     
    JAY6390, Jan 24, 2010 IP
  14. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #14
    [​IMG]
     
    danx10, Jan 24, 2010 IP
  15. Hecky

    Hecky Like a Dungeon Dragon!

    Messages:
    5,656
    Likes Received:
    284
    Best Answers:
    1
    Trophy Points:
    0
    #15
    Guys you're geniuses, thank you very much! :D
     
    Hecky, Jan 24, 2010 IP