17 April 2008
a lightweight mobile device dedection with classic asp
I'm using below function to detect mobile phones coming to my sites.
<%
Function isMobile (ua,accept,ip)
'array accept headers
'--------------------------------------------------------------------------------------------------------
uaAcceptArray=Array( _
"application/vnd.wap.xhtml+xml","text/vnd.wap.wml")
'array known user agents
'--------------------------------------------------------------------------------------------------------
uaArray= Array( _
"symbian" , "series" , "nokia" , "mot-" , "motorola" , "lg-" , "lge" , "nec-" , "lg/" , "samsung" , "sie-" , _
"sec-" , "sgh-" , "sonyericsson" , "sharp" , "windows ce" , "portalmmm" , "o2-" , "docomo" , "philips" , _
"panasonic" , "sagem" , "smartphone" , "up.browser" , "up.link" , "googlebot-mobile" , "googlebot-image" , _
"slurp" , "spring" , "alcatel" , "sendo" , "blackberry" , "opera mini" , "opera 2" , "netfront" , "mobilephone mm" , _
"vodafone" , "avantgo" , "palmsource" , "siemens" , "toshiba" , "i-mobile" , "asus" , "ice" , "kwc" , "htc" , "softbank" , _
"playstation" , "nitro" , "iphone" , "ipod" , "google wireless transcoder" , "t-mobile" , "obigo" , "brew" , "yahooseeker" , _
"msmobot" , "novarra" , "skp" , "openweb" , "zte")
'array common network ips in case we miss user agent
'--------------------------------------------------------------------------------------------------------
ipArray=Array( _
"12.168.76" , "123.49.3" , "125.18.23" , "125.214.1" , "125.5.123.99" , "138.188.101" , "139.7.29" , "148.233.151" , _
"149.254.192" , "149.254.20" , "149.254.200" , "170.51.255" , "190.13.98" , "190.80.12" , "193.108.214" , "193.109.81" , _
"193.113.200" , "193.225.154" , "193.230.161" , "193.253.141" , "193.35.12" , "193.35.13" , "194.176.32" , "194.204.2" , _
"194.48.124" , "195.115.116" , "195.189.14" , "195.222.56" , "195.229.236" , "195.55.47" , "196.11.241" , "196.192.81" , _
"196.200.88" , "196.201.208" , "196.202.236" , "196.207.3" , "196.207.4" , "196.29.161" , "196.30.118" , "196.46.120" , _
"200.179.66" , "200.35.64" , "200.36.161" , "200.40.246" , "200.43.139" , "200.48.69" , "200.49.193" , "200.49.206" , _
"200.72.211" , "200.85.31.72" , "200.85.32" , "200.91.165" , "201.195.82" , "201.24.96" , "202.1.192" , "202.138.126" , _
"202.152.240" , "202.159.21" , "202.160.42" , "202.172.247" , "202.22.194" , "202.3.213" , "202.3.217" , "202.56.4" , _
"202.56.7" , "202.56.7.133" , "202.65.247" , "202.73.198" , "202.73.206" , "202.75.133" , "202.81.69" , "202.93.36" , _
"203.127.153" , "203.135.39" , "203.145.131" , "203.145.134" , "203.162.12" , "203.171.19" , "203.177.91" , "203.189.187" , _
"203.196.249" , "203.20.33.97" , "203.20.35" , "203.78.115" , "203.82.67" , "203.88.1" , "203.88.8" , "203.88.9" , _
"203.92.128" , "203.92.154" , "203.94.229" , "206.47.78" , "208.131.186" , "209.167.5." , "209.183.32" , "209.183.5" , _
"210.212.16" , "210.212.215" , "210.212.31.53" , "212.118.14" , "212.169.66" , "212.17.14" , "212.183.13" , "212.200.246" , _
"212.200.65" , "212.23.97" , "212.252.234" , "212.51.126" , "212.65.63.1" , "212.9.19" , "212.91.99" , "213.132.255" , _
"213.143.52" , "213.149.104" , "213.150.18" , "213.151.208" , "213.161.153" , "213.161.85" , "213.226.13" , "213.229.249" , _
"213.233.128" , "213.42.21" , "213.55.130" , "216.68.79" , "216.9.250.1" , "217.113.74" , "217.116.110" , "217.168.176" , _
"217.171.129" , "217.174.67" , "217.175.164" , "217.200.200" , "217.31.234" , "217.65.192" , "217.71.32" , "217.72.231" , _
"220.231.12" , "221.132.117" , "41.208.11" , "41.208.48.1" , "41.208.50" , "41.220.70" , "41.223.57" , "58.145.190" , _
"58.163.175" , "60.10.2.77" , "62.140.140" , "62.169.66" , "62.201.129" , "62.217.247" , "62.40.38" , "62.44.158" , _
"62.87.37" , "62.87.94" , "66.102.186" , "66.150.33" , "66.54.118" , "66.94.27" , "66.94.9." , "72.46.126.117" , _
"78.93.104.132" , "79.143.100" , "80.125.176." , "80.232.117" , "80.244.97" , "80.250.148" , "80.251.192" , _
"80.251.207.10" , "80.251.207.11" , "80.87.92" , "81.169.63" , "81.18.116" , "81.226.216" , "81.23.22" , "81.237.203" , _
"81.93.86" , "82.113.12" , "82.132.13" , "83.174.40.1" , "83.224.64" , "83.229.15" , "84.241.226" , "85.90.235" , _
"87.101.240" , "87.252.158" , "88.81.159" , "91.140.199" , "91.140.212" , "91.94.217")
'set variables
'--------------------------------------------------------------------------------------------------------
isMobile = False
ua=LCase(ua)
uaArraySize = Ubound(uaArray)
uaAccept=Lcase(accept)
uaAcceptArraySize = Ubound(uaAcceptarray)
ipArraySize = Ubound(ipArray)
uaCheck = True
ipCheck = True
'httpheadersCheck is ready but i dont use it. it's not essential
'httpheadersCheck = True
'do the math
'first check accept headers to see if device is phone.
'if not set uaCheck = True so next for runs
'--------------------------------------------------------------------------------------------------------
For i=0 To uaAcceptArraySize
If instr(uaAcceptArray(i),accept)>0 Then
isMobile=True
'debug
'response.write "<b>uaAccept</b> " &uaAcceptArray(i) &" checked as = " & isMobile&"</br>"
uaCheck = False
ipCheck = False
'httpheadersCheck=False
Exit For
End If
Next
If uaCheck = True then
For x=0 To uaArraySize
If instr(ua,uaArray(x))>0 then
isMobile=True
'debug
'response.write "<b>uaCheck</b> " & uaArray(x) &" checked as = " & isMobile&"</br>"
ipCheck = False
'httpheadersCheck=False
Exit For
End If
Next
End if
If ipCheck = True then
For y=0 To ipArraySize
If instr(ip,ipArray(y))>0 then
isMobile=True
'debug
'response.write "<b>ipCheck</b> " &ipArray(y) &" checked as = " & isMobile&"</br>"
'httpheadersCheck=False
Exit For
End If
Next
End if
'If httpheadersCheck=True Then
'If isEmpty(Request.ServerVariables("HTTP_X_UP_SUBNO"))=False Then
'isMobile=True
'End If
'If isEmpty(Request.ServerVariables("HTTP_XID"))=False Then
'isMobile=True
'End If
'If isEmpty(Request.ServerVariables("HTTP_CLIENTID"))=False Then
'isMobile=True
'End If
'If isEmpty(Request.ServerVariables("HTTP_X_PROFILE"))=False Then
'isMobile=True
'End If
'End If
End Function
%>
Free Classic Asp Wap/Mobile Chat
I have created this simple wml chat couple of years back. It is NOT maintained anymore but I'm sure it would be a good strat for some people.
Download asp-wml-chat.rar (25.42 kb)
On the fly video thumbnailing with Movie Thumbnailer & Classic Asp
Here is another simple code to get thumbnails of uploaded videos.
You need to;
- Get MTN from http://moviethumbnail.sourceforge.net/index.en.html
- Extract it in a folder called thumbnailer under your web root
- Get ASPexec ASPEXEC.rar (135.80 kb)Install aspexec.dll to your server (regsvr32 %pathtoaspexe%)
- Create an upload script with your favorite upload component
- Edit your upload script and insert below code after upload process
<%thumbnailpath=Server.Mappath("thumbnails")
Set objExecutor = Server.CreateObject("ASPExec.Execute")
objExecutor.Application = Server.Mappath("thumbnailer/mtn.exe")
objExecutor.TimeOut = 9000
objExecutor.Parameters = "-b 1 -j 100 -o .jpg -c 1 -r 1 -i -t -P -w 0 -O "&thumbnailpath&"\thumbnail.jpg"
objExecutor.ShowWindow = False
Set objExecutor = Nothing
%>
On the fly video encoding with classic ASP and ffmpeg
Finding proper information about encoding videos uploaded to your site is quite hard. I have created couple of sites where users would upload videos and then script would take thumbnail of the video but couldn't managed to re-encode the video and/or insert a logo in it like those big companies who has the money and human power to do it.
Not anymore :). After 5 days i have managed to encode uploaded video en insert whatever i want in it. Code below can be implemented to run on the fly but it would be too much resource intensive, so i advise you to create may be an admin page where you can select uploaded videos and encode one by one.
You need;
- latest Ffmpeg (Win32 Shared build with devel libs includes VHooks) from http://arrozcru.no-ip.org/ffmpeg_builds/
- access to your server to set application pool of your site to run as local service (iis manager>application pools>your site's pool>properties>identity > predefined> local system.
Keep in mind that with this setting is a big security compromise, I would isolate it and close access from the internet. - a simple transparent logo in png format to insert in to video
Once you have done those settings use code below in your classic asp code to encode and insert your logo to any uploaded videos. Below code encodes videos as mobile mp4 but you can find information about detailed encoding options from http://ffmpeg.mplayerhq.hu/ffmpeg-doc.html
<%
logo=Server.Mappath("logo.png")
encoderPath=Server.Mappath("bin")
originalFile=Server.Mappath("myfile.wmv")
encodedFile=Server.Mappath("encoded_myfile.wmv")
runme="ffmpeg.exe -i "&originalFile&" -vhook ""vhook/imlib2.dll -x 0 -y 0 -i "&logo&""" -acodec libfaac -ac 1 -ar 12000 -ab 12kb -vcodec mpeg4 -r 15 -s 240x184 -b 128kb "&encodedFile
set WShell = CreateObject("WScript.Shell")
WShell.CurrentDirectory = encoderPath
WShell.run runme, 0, TRUE
set WShell = nothing
%>
Subscribe to Posts [Atom]