CFLib.org – Common Function Library Project

urlExists(u)

Last updated January 3, 2006

Version: 1 | Requires: ColdFusion MX | Library: NetLib

 
Rated 0 time(s). Average Rating: 0

Description:
Checks to see if a particular URL actually exists.

Return Values:
Returns a boolean.

Example:

view plain print about
<cfset list = "http://www.cflib.org,http://www.dfkdhsfjksdfh.com,http://www.cflib.org/fooman.jsp">
<cfloop index="u" list="#list#">
    <cfoutput>Does #u# exist? #urlExists(u)#<br /></cfoutput>
</cfloop>

Parameters:

Name Description Required
u The URL to check. Yes

Full UDF Source:

view plain print about
<!---
 Checks to see if a particular URL actually exists.
 Gus made some changes to handle a unresolving domain.
 
 @param u      The URL to check. (Required)
 @return Returns a boolean. 
 @author Ben Forta (ben@forta.com) 
 @version 1, January 3, 2006 
--->

<cffunction name="urlExists" output="no" returntype="boolean">
    <!--- Accepts a URL --->
    <cfargument name="u" type="string" required="yes">

    <!--- Initialize result --->
    <cfset var result=true>

    <!--- Attempt to retrieve the URL --->
    <cfhttp url="#arguments.u#" resolveurl="no" throwonerror="no" />

    <!--- Check That a Status Code is Returned --->
    <cfif isDefined("cfhttp.responseheader.status_code")>
        <cfif cfhttp.responseheader.status_code EQ "404">
            <!--- If 404, return FALSE --->
            <cfset result=false>
        </cfif>
    <cfelse>
        <!--- No Status Code Returned --->
        <cfset result=false>
    </cfif>
    <cfreturn result>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
15 day(s) ago

James Sleeman James Sleeman added
quickSort
25 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
28 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson