SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict Normal75's Avatar
    Join Date
    Oct 2001
    Location
    Vancouver, Canada
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking domain extenstion help

    hi all,
    i have a site that allows users to add only .ca links. It has come to my attention that i am getting tons (100 entries) of unwanted urls every day and it's been really frustrating trying to go through these urls.

    Now i am hoping to add a code to verify the url before it's being sent to my database for verification. Can someone help me come up with a code that will check the domain extension?

    A format as followed will probably do the work...

    PHP Code:
    function IsEmailAddress($str) {  
      if (
    it is a dot ca domain... ,$str$regs)) {
        return 
    true;
      }
      else {
        return 
    false;
      }

    Please help. thank you.
    ~It will come to me one day~

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Finland
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Try this

    function IsEmailAddress($str) {

    $url_parts = explode(".",$str);

    if($url_parts[count($url_parts)-1] == 'ca') return true;

    return false;

    }

    Try this!

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    PHP Code:
    # incoming url $_GET or _POST
    $url$_REQUEST['url'];
      if(
    stristr($url'.ca') === FALSE) {
       echo 
    'Wrong URL';
      } 
    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Addict Normal75's Avatar
    Join Date
    Oct 2001
    Location
    Vancouver, Canada
    Posts
    245
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the reply..

    tjalonen, your solution didn't work

    Mike, yours work, but it will bypass when you have www.capital.com since .ca is part of the string. But i will use it for now until i find better solution.

    thank you.
    ~It will come to me one day~

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Finland
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    function IsEmailAddress($str) {

    // explodes url parts in array
    $url_parts = explode(".",$str);

    // urls format must be name.ext AND ext-part ca
    if(count($url_parts) >= 2 && $url_parts[count($url_parts)-1] == 'ca') return true;

    return false;

    }

    Now it should work.

  6. #6
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    or you could try something like this instead then.
    PHP Code:
    $url$_REQUEST['url']; 
      if(
    strrchr$url'.' ) != '.ca') { 
       echo 
    'Wrong URL'
      } 
    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •