![]() | |||||||
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: |
I needed this a little while ago, and here is what I have: PHP Code: then use: if ($headers[0] == 1) { code } |
Not everyone has PHP5 ;) |
Updated the code, check first post. |
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: -RageD |
Thanks for answering that for me, RageD. :tu: |
why not just: $var = file_get_contents($url); if ($var == TRUE) { // url is ok } else { // url is invalid } |
What would be the point of getting the URL's content? That'd be useless and inefficient. This function does the same without the burden of gathering content. |
Just set max length to 1 to keep from grabbing the whole thing.. Beats using a gigantic function, overkill to me. Much less processing time and lower load. |
| All times are GMT -7. The time now is 10:14 PM. |
Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0