SearchSearch   MemberlistMembers   RegisterRegister   ProfileProfile   Log inLog in 

How To Validate Links Using ASP

 
Post new topic   Reply to topic    Open Hosting Internet Solutions Forum Index -> Articles and Tutorials -> Server Side Web Development
View previous topic :: View next topic  
Author Message
Nick
Forum Moderator


Joined: 18 Jun 2002
Posts: 3635

PostPosted: Wed Mar 08, 2006 2:39 pm    Post subject: How To Validate Links Using ASP Reply with quote

How To Validate Links Using ASP

Using the XMLHTTP object we can programmatically check the status of a specific URL. This can be useful for checking if files exist on your website.

Sometimes you may wish to check whether a specific link is working or not. Maybe you want to check to see if the server is responding, or if a file exists. Well now you do this from directly within your ASP code!
Code:
<%
Function URLStatus(strURL)
Dim objXMLHTTP, strReturnStatus
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")

objXMLHTTP.Open "GET", "http://www.openhosting.co.uk/default.asp", False
objXMLHTTP.Send

strReturnStatus = objXMLHTTP.Status
Set objXMLHTTP = Nothing

URLStatus = strReturnStatus
End Function

Dim strfrmURL
strfrmURL = CStr(Request.Form("frmURL"))
If strfrmURL <> "" Then

If URLStatus(strfrmURL) = "200" Then
Response.Write "Link is working."
Else
Response.Write "Link is not working: " & URLStatus(strfrmURL)
End If

End If
%>


This function receives a parameter in the form of a URL or IP address. It uses the XMLHTTP object and opens the URL. A returned value of ?200? means the link is successful (server responds and/or file exists) and a value of anything else is specific to the error. For example, if the file does not exist then ?404? will be returned.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Open Hosting Internet Solutions Forum Index -> Articles and Tutorials -> Server Side Web Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.11 © 2001, 2002 phpBB Group
FAQClick here for help using the phpBB forum