Server - Inline Hello World Example

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
skider86
Posts: 5
Joined: Mon Nov 17, 2008 4:08 am

Server - Inline Hello World Example

Post by skider86 » Wed Oct 12, 2011 8:03 pm

I copied the text below from a RunRev server (cannot post the URL apparently due to my account lacking permission, so you will have to trust me that I copied/pasted it correctly) and saved as a .html file. When I visit the .html page I only see
hello world" ?>
on the server instead of displaying what I would expect to be a heading with the text "hello world". If I place the three lines of LiveCode in a file named hello.lc and run off the server I get the appropriate text. What does one have to do in order to get the server to evaluate the block of LiveCode in the .html file?


<html>
<head></head>
<body>
<?lc
put "<H1>hello world</H1>"
?>
</body>
</html>

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Server - Inline Hello World Example

Post by Klaus » Wed Oct 12, 2011 8:34 pm

Hi Skider,
skider86 wrote:What does one have to do in order to get the server to evaluate the block of LiveCode in the .html file?
Nothing, this is not possible!

The server decides by the file SUFFIX what to do:
xxx.lc = it will start the LiveCode server engine to process that file
xxx.html = it will call Apache (or what WEB-server is currently installed) to process that file
xxx.php = it will call the PHP engine on the server to process hat file


Best

Klaus

skider86
Posts: 5
Joined: Mon Nov 17, 2008 4:08 am

Re: Server - Inline Hello World Example

Post by skider86 » Wed Oct 12, 2011 8:52 pm

Thanks for the kind response Klaus. I guess my experience with PHP on other hosts in the past have clouded things for me since it was trivial to go from a static page to a dynamic page over time by sprinkling a little PHP around. What is the best practice to shield these file extensions from the browser so a visitor only bookmarks/shares a .html page?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Server - Inline Hello World Example

Post by Klaus » Wed Oct 12, 2011 9:19 pm

Hi Skider,
skider86 wrote:What is the best practice to shield these file extensions from the browser so a visitor only bookmarks/shares a .html page?
sorry, no idea!

But do you think that the user will really bother whether he bookmarks an URL with the suffix .lc instead of .html or .php or .asp or .jsp or whatever? :D
I don't think so, as long as the user gets the exspected content.


Best

Klaus

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Server - Inline Hello World Example

Post by mwieder » Wed Oct 12, 2011 9:34 pm

Shouldn't that be

Code: Select all

<?lc
put "<H1>hello world</H1>"
inside a helloworld.lc file? And then in the helloworld.html file

Code: Select all

<html>
<head></head>
<body>
<?lc
include "helloworld.lc"
?>
</body>
</html>
It's no more compilcated that php, and what's presented to the user's browser is the *result* of the .lc file, not the file itself, so I think it does what you're asking.

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

Re: Server - Inline Hello World Example

Post by sturgis » Thu Oct 13, 2011 3:21 am

mwieder wrote:Shouldn't that be

Code: Select all

<?lc
put "<H1>hello world</H1>"
inside a helloworld.lc file? And then in the helloworld.html file

Code: Select all

<html>
<head></head>
<body>
<?lc
include "helloworld.lc"
?>
</body>
</html>
It's no more compilcated that php, and what's presented to the user's browser is the *result* of the .lc file, not the file itself, so I think it does what you're asking.
To get it to parse the LC script in a .html file one would have to add the extension (addhandler/action stuff like you do with .lc and earlier .irev)

I -think- that if SSI (server side includes) are on, this can be done..
<!--#include FILE="myfile.lc" --> so that the server will parse the myfile.lc and put the results into the html page, but again, that would require SSI to be enabled, and all your code would be broken out into separate .lc files.

Of course, javascript could be used to include an external page inline also.

So, in order to answer this question..
on the server instead of displaying what I would expect to be a heading with the text "hello world". If I place the three lines of LiveCode in a file named hello.lc and run off the server I get the appropriate text. What does one have to do in order to get the server to evaluate the block of LiveCode in the .html file?
If you have direct access to control the server, I am pretty sure you can edit the conf files to add .html as a 'handled' extension that points to livecode server, the same way .lc was set up. If you DON'T have direct access to the server, its very likely that you can use a .htaccess file to accomplish the task as explained here. http://lessons.runrev.com/m/4070/l/36655 Just change .lc to .html (or keep both)

Of course the downside of this is that EVERY .html page will be parsed whether it needs it or not.

There may be other reasons to not use .html as a parsed extension, but hopefully this will work for you.

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

Re: Server - Inline Hello World Example

Post by BarrySumpter » Thu Oct 13, 2011 10:46 pm

Big thanks to Sturgis for that reply.
Very nice!
Love these verbose answers.

In case anyoine is already using IIS or wants to (like me):
LiveCode Server on WinXP32 IIS 5.1 - easy setup (no need for Apache):
http://forums.runrev.com/viewtopic.php? ... 562#p41010
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.

Post Reply