[advanced search]
NamePros Domain Auction
Live Event This Thursday at 6PM EDT - Prebidding open now
25 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 04-11-2007, 12:52 PM   · #1
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (136)
Join Date: Mar 2005
Posts: 4,054
NP$: 9.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund
Check if a URL exists.

Howdy.

This simple function will check if a url is valid (going by parse_url()) and if it's 'online' - by seeing if it returns a 302, 301, or 200 status code.

EDIT: 3/4/2008, updated to more efficient.

PHP Code:
<?php

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'] : '/';
    
$path .= (isset($url['query'])) ? "?$url[query]" : '';

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

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

?>


Please register or log-in into NamePros to hide ads
__________________
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator

Last edited by SecondVersion : 03-04-2008 at 05:29 PM.
SecondVersion is offline   Reply With Quote
Old 04-15-2007, 05:04 PM   · #2
bobby9101
NamePros Regular
 
Name: Bobby Eubank
Trader Rating: (30)
Join Date: Jun 2005
Posts: 873
NP$: 170.25 (Donate)
bobby9101 is a name known to allbobby9101 is a name known to allbobby9101 is a name known to allbobby9101 is a name known to allbobby9101 is a name known to allbobby9101 is a name known to all
I needed this a little while ago, and here is what I have:
PHP Code:
function url_exists($url) {
@
$headers = get_headers($url);
    return
preg_match('/^HTTP\/\d\.\d\s+(200|301|302)/', $headers[0]);
}

then use:
if ($headers[0] == 1) {
code
}
__________________
EAUA.NET - ETIH.NET - IBOV.NET - JJOJ.NET - NNNQ.NET - OIAI.NET - UBOK.NET - WUSI.NET - XVVX.net - XUFU.NET - ZERY.NET

http://pleep.info - http://americasurf.info - http://bepper.info - http://missingip.info
bobby9101 is online now   Reply With Quote
Old 04-15-2007, 05:17 PM   · #3
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (136)
Join Date: Mar 2005
Posts: 4,054
NP$: 9.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund
Originally Posted by bobby9101
I needed this a little while ago, and here is what I have:
PHP Code:
function url_exists($url) {
@
$headers = get_headers($url);
    return
preg_match('/^HTTP\/\d\.\d\s+(200|301|302)/', $headers[0]);
}

then use:
if ($headers[0] == 1) {
code
}


Not everyone has PHP5
__________________
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator
SecondVersion is offline   Reply With Quote
Old 03-04-2008, 05:28 PM   · #4
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (136)
Join Date: Mar 2005
Posts: 4,054
NP$: 9.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund
Updated the code, check first post.
__________________
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator
SecondVersion is offline   Reply With Quote
Old 04-10-2008, 05:26 AM   · #5
abcde
NamePros Regular
 
Name: Steven
Trader Rating: (11)
Join Date: Feb 2005
Posts: 473
NP$: 1393.00 (Donate)
abcde has a spectacular aura aboutabcde has a spectacular aura about
Originally Posted by SecondVersion
Updated the code, check first post.



I don't get it, how to use that code above? sorry, im a newbie with php
abcde is offline   Reply With Quote
Old 04-10-2008, 04:49 PM   · #6
RageD
Senior Member
 
Name: Dennis
Location: Joliet, Illinois
Trader Rating: (38)
Join Date: Apr 2005
Posts: 1,110
NP$: 402.00 (Donate)
RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold
Child Abuse
Originally Posted by abcde
I don't get it, how to use that code above? sorry, im a newbie with php



First, you need a webhost which supports PHP or to install it on your own PC. But on your own PC you need to also install a webserver and it's a real hassle so it's easier to have a webhost with this.

Then, input this script in to a file called file.php (or whatever_you_want.php) and save and close the file.

Now in SecondVersion's script he created the function called $is_valid_url($url); so what you'll want to do to see if a URL exists: (within the same file that the function is in [or if it's included for that matter])

PHP Code:
<?php
// Test script. Function created by SecondVersion
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'] : '/';
    
$path .= (isset($url['query'])) ? "?$url[query]" : '';

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

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

if(
is_valid_url("http://namepros.com"))
{
    echo(
"w00t for Namepros.com! It's alive!");
}else{
    echo(
"Oh no! Where did NamePros go!?! :(");
}

?>


-RageD
RageD is online now   Reply With Quote
Old 04-17-2008, 05:11 AM   · #7
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (136)
Join Date: Mar 2005
Posts: 4,054
NP$: 9.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund
Thanks for answering that for me, RageD.
__________________
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator
SecondVersion is offline   Reply With Quote
Reply

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Exdon Venta de dominios Compra tu dominio Get Me Visits
Advertise your business at NamePros
All times are GMT -7. The time now is 04:37 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0