NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page URL Validation (PHP)

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 08-17-2009, 05:09 AM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Jan 2006
Posts: 322
X_GuardiaN_X will become famous soon enoughX_GuardiaN_X will become famous soon enough
 



URL Validation (PHP)


I am developing a website that is heavy on domain names, so a good URL validation function is really important. I have searched a lot but haven't been able to find one that seems to work very well.

Can anybody help me out?
X_GuardiaN_X is offline   Reply With Quote
Old 08-17-2009, 09:52 AM   #2 (permalink)
NamePros Regular
 
chadsmith's Avatar
Join Date: Jul 2008
Location: Wichita, KS
Posts: 287
chadsmith is just really nicechadsmith is just really nicechadsmith is just really nicechadsmith is just really nice
 




Are you just verifying the URL exists? If so, you can do that by grabbing the headers. Try:

PHP Code:
function url_exists($url){
    @
$headers=get_headers($url);
    return 
preg_match('/^HTTP\/\d\.\d\s+(200|301|302)/',$headers[0]);

It will return true as long as the URL returns 200 (ok), 301 (permanently redirected), or 302 (temporarily redirected). get_headers is a PHP 5 function.
chadsmith is offline   Reply With Quote
Old 08-17-2009, 10:44 AM   #3 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



if you're trying to validate that the text input by a user really is a url string, you could do something like filter_var($url, FILTER_VALIDATE_URL); assuming you hvae php5
nasaboy007 is offline   Reply With Quote
Old 08-29-2009, 03:35 PM   #4 (permalink)
New Member
Join Date: Aug 2009
Posts: 14
OverDark is an unknown quantity at this point
 



if you have PEAR maybe it works like this

PHP Code:
$URLObject Net_URL($URL);
????: NamePros.com http://www.namepros.com/programming/603820-url-validation-php.html
if(
$URL == $URLObject->getURL()){
// action if the url is valid
} else {
// action if url is invalid

though i'm not sure if it works in PHP 5
OverDark is offline   Reply With Quote
Old 09-04-2009, 03:32 AM   #5 (permalink)
New Member
Join Date: Sep 2009
Posts: 4
Hanratty is an unknown quantity at this point
 



function isValidURL($url)
{
return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}




if(!isValidURL($fldbanner_url))
{
$errMsg .= "* Please enter valid URL including http://<br>";
}
__________________
Listen to Emails
Last edited by Hanratty; 09-20-2009 at 08:30 AM.
Hanratty is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:31 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger