dpinto04
asked on
ASP Function to validate a URL
Hi,
I need an ASP funnction that can validate a URL from a form.
Could you pls direct me to one.
Thanx
I need an ASP funnction that can validate a URL from a form.
Could you pls direct me to one.
Thanx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here's an example - http://levinecentral.com/test/url_exists.asp
Here's the source:
<html>
<head><title>Check if URL exists</title></head>
<body>
<form method="POST" action="url_exists.asp">
<p><input type="text" name="formURL" size="40" value="<%=request.form("fo rmURL")%>" </p>
<p><input type="submit" value="Check" name="B1"></p>
<%
if request.form("formURL") > "" then
response.write("<hr><br>")
Dim objXMLHTTP, strReturnStatus
Set objXMLHTTP = Server.CreateObject("Micro soft.XMLHT TP")
objXMLHTTP.Open "GET", request.form("formURL"), False
objXMLHTTP.Send
strReturnStatus = objXMLHTTP.Status
Set objXMLHTTP = Nothing
if strReturnStatus = "200" then
response.write("URL " & request.form("formURL") & " was found.")
else
response.write("URL " & request.form("formURL") & " was NOT found.")
end if
end if
%>
</form>
</body>
</html>
Here's the source:
<html>
<head><title>Check if URL exists</title></head>
<body>
<form method="POST" action="url_exists.asp">
<p><input type="text" name="formURL" size="40" value="<%=request.form("fo
<p><input type="submit" value="Check" name="B1"></p>
<%
if request.form("formURL") > "" then
response.write("<hr><br>")
Dim objXMLHTTP, strReturnStatus
Set objXMLHTTP = Server.CreateObject("Micro
objXMLHTTP.Open "GET", request.form("formURL"), False
objXMLHTTP.Send
strReturnStatus = objXMLHTTP.Status
Set objXMLHTTP = Nothing
if strReturnStatus = "200" then
response.write("URL " & request.form("formURL") & " was found.")
else
response.write("URL " & request.form("formURL") & " was NOT found.")
end if
end if
%>
</form>
</body>
</html>
Here's the same code with an "on error" to handle missing domains..
<html>
<head><title>Check if URL exists</title></head>
<body>
<form method="POST" action="url_exists.asp">
<p><input type="text" name="formURL" size="40" value="<%=request.form("fo rmURL")%>" </p>
<p><input type="submit" value="Check" name="B1"></p>
<%
On Error Resume Next
if request.form("formURL") > "" then
response.write("<hr><br>")
Dim objXMLHTTP, strReturnStatus
Set objXMLHTTP = Server.CreateObject("Micro soft.XMLHT TP")
objXMLHTTP.Open "GET", request.form("formURL"), False
objXMLHTTP.Send
strReturnStatus = objXMLHTTP.Status
Set objXMLHTTP = Nothing
if strReturnStatus = "200" then
response.write("URL " & request.form("formURL") & " was found.")
else
response.write("URL " & request.form("formURL") & " was NOT found.")
end if
end if
%>
</form>
</body>
</html>
<html>
<head><title>Check if URL exists</title></head>
<body>
<form method="POST" action="url_exists.asp">
<p><input type="text" name="formURL" size="40" value="<%=request.form("fo
<p><input type="submit" value="Check" name="B1"></p>
<%
On Error Resume Next
if request.form("formURL") > "" then
response.write("<hr><br>")
Dim objXMLHTTP, strReturnStatus
Set objXMLHTTP = Server.CreateObject("Micro
objXMLHTTP.Open "GET", request.form("formURL"), False
objXMLHTTP.Send
strReturnStatus = objXMLHTTP.Status
Set objXMLHTTP = Nothing
if strReturnStatus = "200" then
response.write("URL " & request.form("formURL") & " was found.")
else
response.write("URL " & request.form("formURL") & " was NOT found.")
end if
end if
%>
</form>
</body>
</html>
ASKER
The above script gives me:
msxml3.dll (0x800C0005)
The system cannot locate the resource specified.