Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: URL validator

  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    USA
    Posts
    99
    Thanks
    24
    Thanked 0 Times in 0 Posts

    URL validator

    PHP Code:
    function is_valid_url $url )
    {
            
    $url = @parse_url($url);

            if ( ! 
    $url) {
                return 
    false;
            }

            
    $url array_map('trim'$url);
            
    $url['port'] = (!isset($url['port'])) ? 80 : (int)$url['port'];
            
    $path = (isset($url['path'])) ? $url['path'] : '';

            if (
    $path == '')
            {
                
    $path '/';
            }

            
    $path .= ( isset ( $url['query'] ) ) ? "?$url[query]" '';

            if ( isset ( 
    $url['host'] ) AND $url['host'] != gethostbyname $url['host'] ) )
            {
                if ( 
    PHP_VERSION >= )
                {
                    
    $headers get_headers("$url[scheme]://$url[host]:$url[port]$path");
                }
                else
                {
                    
    $fp fsockopen($url['host'], $url['port'], $errno$errstr30);

                    if ( ! 
    $fp )
                    {
                        return 
    false;
                    }
                    
    fputs($fp"HEAD $path HTTP/1.1\r\nHost: $url[host]\r\n\r\n");
                    
    $headers fread $fp128 );
                    
    fclose $fp );
                }
                
    $headers = ( is_array $headers ) ) ? implode "\n"$headers ) : $headers;
                return ( bool ) 
    preg_match '#^HTTP/.*\s+[(200|301|302)]+\s#i'$headers );
            }
            return 
    false;

    what's wrong with this? It seems to work great and haven't had any problems but it didn't work when i tried http://www.zyrv.com/
    Just wondering why?

  • #2
    New Coder
    Join Date
    Mar 2003
    Location
    USA
    Posts
    99
    Thanks
    24
    Thanked 0 Times in 0 Posts
    Is it because it's a new site?

    Bump


  •  

    Posting Permissions

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