iHonda Posted January 7, 2009 Share Posted January 7, 2009 (edited) Well after searching through the help file and the forum I couldn't find anything that could check if a URL was valid, so I wrote my own function. I hope this is useful to at least one other person even though it is so simple. I was thinking about submitting it to be an included UDF but idk yet.Without further ado or bull.. heres my function:#cs Name..........: _INetFileExist Description...: Checks to see if given URL is valid Syntax........: _INetFileExist($sUrl) Parameters....: None Return Values.: Success - 1 Failure - 0 Author........: Ikaika Honda Modified......: Remarks.......: Related.......:INetGetSize, FileExists Link..........; Example.......: Yes #ce Local $sUrl Func _INetFileExist(Const $sUrl) $size = InetGetSize($sUrl) If $size = 0 Then Return(0) Else Return (1) EndIf EndFuncoÝ÷ Ù«¢+Ù%}%9Ñ¥±á¥ÍÐ ÅÕ½Ðí¡ÑÑÀè¼½ÝÝܹ¡½¹Í¥¹Ì¹½´ÅÕ½Ðì¤Q¡¸(%5Í ½à Ä°ÅÕ½ÐíáµÁ±ÅÕ½Ðì°ÅÕ½ÐíUI0á¥ÍÑÌÌÌìÅÕ½Ðì¤)±Í(%5Í ½à Ä°ÅÕ½ÐíáµÁ±ÅÕ½Ðì°ÅÕ½ÐíUI0½Ì9½Ðá¥ÍÐÌÌìÅÕ½Ðì¤)¹%edit: forgot to use the autoit tags See Prog@ndy's post for a function that works with php files as well [click here]peace,Z Edited January 8, 2009 by Zmaster A great place to start Autoit 1-2-3 Link to comment Share on other sites More sharing options...
gseller Posted January 7, 2009 Share Posted January 7, 2009 After testing I found a bug... If you try one of my sites http://www.linzfotos.com/ which uses an index.php initial page it reports not valid. If the initial pageis an index.htm or index.html it works, example here: http://www.cards-ok.org/ Link to comment Share on other sites More sharing options...
iHonda Posted January 8, 2009 Author Share Posted January 8, 2009 hmm ok ill get that fixed asap A great place to start Autoit 1-2-3 Link to comment Share on other sites More sharing options...
Xand3r Posted January 8, 2009 Share Posted January 8, 2009 (edited) nice work Local $sUrl Func _INetFileExist(Const $sUrl) $size = InetGetSize($sUrl) If $size = 0 Then Return 0 Else Return $size EndIf EndFunc returning the size if it is found or 0 if not is far more usefull Edited January 8, 2009 by TheMadman Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro Link to comment Share on other sites More sharing options...
iHonda Posted January 8, 2009 Author Share Posted January 8, 2009 (edited) nice work Local $sUrl Func _INetFileExist(Const $sUrl) $size = InetGetSize($sUrl) If $size = 0 Then Return 0 Else Return $size EndIf EndFunc returning the size if it is found or 0 if not is far more usefull indeed it is good idea... or maybe include that as an option.. yeah.. that would be good.... i can do that thanks for the idea @gseller: after testing the script and the INetGetSize function I discovered that INetGetSize doesn't return the size of .php extensions for some reason this could possibly take longer than expected. I'll post progress updates as progress is made. thanks, ihonda Edited January 8, 2009 by Zmaster A great place to start Autoit 1-2-3 Link to comment Share on other sites More sharing options...
ProgAndy Posted January 8, 2009 Share Posted January 8, 2009 This function should work with PHP, too $URL = "http://progandy.pr.funpic.de/index.php" MsgBox(0, '', _InetFileExists($URL)) Func _InetFileExists($URL) ; ----------------------- ; by Prog@ndy ; ----------------------- $URL = StringRegExpReplace($URL,"(.*?://)","") $URL = StringRegExp($URL,"\A(.*?)(?:/(.*))?\Z",3) If UBound($URL) = 1 Then ReDim $URL[2] TCPStartup() Local $port = StringRegExp($URL[0],":(d*)\Z",3) If @error Then $port = 80 Else $port = $port[0] $URL[0] = StringTrimRight($URL[0],StringLen($port)) EndIf Local $IP = TCPNameToIP($URL[0]) If @error Then Return SetError(1,0,0*TCPShutdown()) Local $conn = TCPConnect($IP,$port) If @error Then Return SetError(2,0,0*TCPShutdown()) TCPSend($conn,"HEAD /" & $URL[1] & " HTTP/1.1" & @CRLF & "Host: " & $URL[0] & @CRLF& @CRLF) Local $recv = "" Do $recv &= TCPRecv($conn,1024) Until @error Or StringInStr($recv,@CRLF&@CRLF) TCPCloseSocket($conn) TCPShutdown() $recv = StringSplit($recv,@CRLF,1) If StringInStr($recv[1],"200") Then Return 1 Return 0 EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
gseller Posted January 8, 2009 Share Posted January 8, 2009 nice work Local $sUrl Func _INetFileExist(Const $sUrl) $size = InetGetSize($sUrl) If $size = 0 Then Return 0 Else Return $size EndIf EndFunc returning the size if it is found or 0 if not is far more usefull TheMadmans function seems to work well for this issue Link to comment Share on other sites More sharing options...
iHonda Posted January 8, 2009 Author Share Posted January 8, 2009 thanks guys guess i still need some study, thanks for solving the problem for me ProgAndy, bummers i couldn't figure it out... at least i can still claim proof of concept im gonna keep workin on this maybe figure a simpler way to do it A great place to start Autoit 1-2-3 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now