ASP script to check for PC or Mobile Browser- convert to LC?

Are you using LiveCode to create server scripts or CGIs?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

ASP script to check for PC or Mobile Browser- convert to LC?

Post by BarrySumpter » Wed Mar 07, 2012 4:37 am

This redirect works on my android.
Could I / Should I convert to LC server side scripts?

Also, in my index.asp code, mu

Code: Select all

<?LC Put "<b>Hello World!" ?>
doesn't work.

But in index.lc it does.
Do I need a LiveCode compiler directive at the top like in asp pages for vbscript?

Code: Select all

<%@ Language = "VBScript" %>

Redirect Code:
Darn, don't have access to iPhone at the mo.

Code: Select all

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 2</title>
</head>

<body>

<%
'Option Explicit
Dim user_agent, mobile_browser, Regex, match, mobile_agents, mobile_ua, i, size
 
user_agent = Request.ServerVariables("HTTP_USER_AGENT")
 
mobile_browser = 0
 
Set Regex = New RegExp
With Regex
   .Pattern = "(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm)"
   .IgnoreCase = True
   .Global = True
End With
 
match = Regex.Test(user_agent)
 
If match Then mobile_browser = mobile_browser+1
 
If InStr(Request.ServerVariables("HTTP_ACCEPT"), "application/vnd.wap.xhtml+xml") Or Not IsEmpty(Request.ServerVariables("HTTP_X_PROFILE")) Or Not IsEmpty(Request.ServerVariables("HTTP_PROFILE")) Then
   mobile_browser = mobile_browser+1
end If
 
mobile_agents = Array("w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq", "bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang", "doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi", "keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo", "midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-", "newt", "noki", "oper", "palm", "pana", "pant", "phil", "play", "port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-", "send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar", "sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-", "upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp", "wapr", "webc", "winw", "winw", "xda", "xda-")
size = Ubound(mobile_agents)
mobile_ua = LCase(Left(user_agent, 4))
 
For i=0 To size
   If mobile_agents(i) = mobile_ua Then
      mobile_browser = mobile_browser+1
      Exit For
   End If
Next
 
 
'If mobile_browser>0 Then
'   Response.Write("Mobile!")
'Else
'   Response.Write("Not mobile!")
'End If


If mobile_browser>0 Then
   Response.Redirect("LooksLikeMobileBrowser.asp")
Else
   Response.Redirect("http://www.barrysumpter.com")
End If
 
%>

</body>

</html>
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: ASP script to check for PC or Mobile Browser- convert to

Post by sturgis » Wed Mar 07, 2012 5:21 am

When livecode server is set up a handler is added to the server config files (or you can use the .htaccess method) and the extension to be used for that handler is defined. I don't know enough about how asp works to give a definitive answer, but it might be possible to add .asp as one of the livecode handled extensions without affecting the asp functionality, but I don't know for sure. I like this idea, so if I get time I may try it just to see if I can get both php and lc going in the same page.

If I get this done and it works I may post the results here on the chance that it would apply to .asp stuff also.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: ASP script to check for PC or Mobile Browser- convert to

Post by BarrySumpter » Wed Mar 07, 2012 5:35 am

Always good to read your posts sturgis.
Would be greatful if and when you could find the time.
No prob if not.

LC Server Doco (for me):
http://www.runrev.com/developers/documentation/server/
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: ASP script to check for PC or Mobile Browser- convert to

Post by sturgis » Wed Mar 07, 2012 12:26 pm

After reading quite a bit, don't think its possible to make both inline asp and inline lc functional. Seems to be an either/or situation. However, if you don't mind breaking things up in to smaller files, and you have SSI turned on, you can use the <!--#include file="time.lc" --> include directive to include lc content inline on the fly. For a quick explanation check here. http://w3schools.com/asp/asp_incfiles.asp Should work to include php, .lc, whatever.

Not sure what security issues there might be with using Server Side Includes so some additional research would be a good idea.

If you find out i'm mistaken (pretty common) and learn of ways to include lc script inline with asp or vice versa an update here would be cool.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

LC cosmetic technique for enlarging font if on Android Mobil

Post by BarrySumpter » Thu Mar 15, 2012 3:18 am

Cool. thanks again Sturgis for your research and findings post.

----

Hi all,

I'm now researching how to communicate from Android to the LC Server.

But I've started with how to communicate from web page to web page:

LiveCode Server: http://www.runrev.com/developers/documentation/server/

Item 3.3 - Using Post / Get

Starting with Post example:
How do I handle user input using LiveCode Server?
http://lessons.runrev.com/spaces/lesson ... de-Server-

Code: Select all

<h1>Enter your credentials</h1>
<form action="http://www.my-site.com/my_script.lc" method="POST">
     <p>Username: <input type="text" name="username" value="" /></p>
     <p>Password: <input type="password" name="password" value="" /></p>
     <p><input type="submit" value="Login" /></p>
     <input type="hidden" name="form_submitted" value="true" />
</form>
This html script for UserName and PassWord look fine on my Desktop browser.
But super small on my Android HD2 default browser.

Is there a LiveCode cosmetic technique I can use with the ASP script from the first post in this thead
to enlarge the font if its on android?

Or are these techniques really better iplemented in ASP or HTML script and not LC scripts?
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: ASP script to check for PC or Mobile Browser- convert to

Post by BarrySumpter » Thu Mar 15, 2012 4:32 am

A quick nap and:
I could have one Login for mobile with larger font.
And another Login for desktop with normal font.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

sadilza
Posts: 1
Joined: Tue Jan 29, 2013 12:05 pm
Contact:

Re: ASP script to check for PC or Mobile Browser- convert to

Post by sadilza » Tue Jan 29, 2013 12:12 pm

BarrySumpter wrote:A quick nap and:
I could have one Login for mobile with larger font.
And another Login for desktop with normal font.
have you done it?? please guide me too

Post Reply

Return to “CGIs and the Server”