Check that website is valid?

Discussion in 'PHP' started by crazyryan, Jan 29, 2007.

  1. #1
    Hey, basically I have a link submitting script although the user can enter "dfdf"
    and it'll still process it. Can anyone help me in checking that the website/sub-domain is valid?
     
    crazyryan, Jan 29, 2007 IP
  2. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you just want to check if a URL entered is valid, you can try this:
    
    $url = $_POST['url'];
    if (preg_match("/^(http(s*):\/\/|ftp:\/\/)((\w+\.)+)\.[a-z]{2,}$/i", $url)) {
    echo "Valid URL";
    }
    else {
    echo "Invalid URL";
    }
    PHP:
    This checks also for http(s) and ftp at the beginning.

    HTH, cheers! :)
     
    picouli, Jan 29, 2007 IP
  3. KC TAN

    KC TAN Well-Known Member

    Messages:
    4,792
    Likes Received:
    353
    Best Answers:
    0
    Trophy Points:
    155
    #3
    You can try:
    
    $link='http://www.google.com';
    
    //grab content
    $html= @file_get_contents($link);
    
    if($html) echo 'Valid page';
    else echo 'No page content';
    
    
    PHP:
    Hope it helps :)
     
    KC TAN, Jan 29, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Why download the entire page?

    If you want to take this style, use fopen instead of reading the entire page.

    Peace,
     
    Barti1987, Jan 29, 2007 IP