Building web applets with Haskell and PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Dear nice PHP people out there!

In the past I used Java to built web applets, but my current main
language is Haskell and I am thinking of providing the same
functionality, this time computed on the server side and by means of
PHP as the glue language.

The basic idea of my new Haskell-PHP applets is always the same: the
user can input some expression (according to a primitive and problem-
dependent syntax), the expression is evaluated and returned . The
general setup is:
1. The user sees a php/html page with a form and a textarea. She
inputs an expression, say "(4 + 3) - 1" and presses the submit button.
2. The content of the textarea is written to a standard input/output
file, say "standardIO.txt".
3. PHP calls an executable, say "SimpleTermEval",  which is the
compiler result of some Haskell program, for example by calling the
statement system("./SimpleTermEval");
4. The executable reads the user input from "standardIO.txt",
evaluates it and writes the result (say "6") back to "standardIO.txt".
5. PHP then reads the content of "standardIO.txt" and displays it for
the user.

I tried to implement this as follows:

<form action=<?php $_SERVER["PHP_SELF"] ?>
      method="POST" enctype="text/plain">
  <textarea name="userinput" rows="10" cols="80"></textarea>
  <input type="submit"></input>

    if ( $_POST['userinput'] ) {
        $filename = "standardIO.txt" ;
        $input = $_POST['userinput'] ;
        file_put_contents($filename,$input) ;
        system ( "/.SimpleTermEval" ) ;
        $output = file_get_contents($filename) ;
        echo "<blockquote> $output </blockquote>" ;
    } ;

But when I try to use it on my local host (ubuntu linux), I receive a
strange error message after the submission:

Not Found
The requested URL /apps/method="post" was not found on this server.
Apache/2.2.9 (Ubuntu) mod_auth_kerb/5.3 DAV/2 SVN/1.5.1
mod_lisp2/1.3.1 PHP/5.2.6-2ubuntu4 with Suhosin-Patch mod_python/3.3.1
Python/2.5.2 mod_perl/2.0.4 Perl/v5.10.0 Server at localhost Port 80

What am I doing wrong?

Re: Building web applets with Haskell and PHP

On Wed, 11 Feb 2009 21:42:17 -0800 (PST), noknok

Quoted text here. Click to load it

I *think* you need:
<form action="<php echo $_SERVER["PHP_SELF"] ?>"

i.e. you need to tell PHP to echo/print the URL
Free personal divertable Phone number: <

Re: Building web applets with Haskell and PHP

noknok escribió:
Quoted text here. Click to load it
Quoted text here. Click to load it

The first troubleshooting technique you must get used to is inspecting
the HTML your script generates. Most web browsers have a View-> Source
menu. If you do so you'll notice that:

- You are not printing $_SERVER["PHP_SELF"]
- You are not using quotes

In any case, action="" is normally enough.

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor al baño María:

Re: Building web applets with Haskell and PHP

Thank you David and Alvaro, you were right.
I miss the routine in PHP and I make a lot of mistakes.

A couple of hours later and I was able to eliminate some more. For
example, if I leave in the attribute
in the form tag, then the POST method doesn't work, only the GET
method -- for whatever reason. So, that's eliminated now.
Also, it should have been
  system ( "./SimpleTermEval" ) ;
instead of
  system ( "/.SimpleTermEval" ) ;
of course.

Well, now things are working on my "localhost" and I can polish the
stuff. The next problem will probably be the upload to my host
provider. Months ago I realized, that they had some kind of safe mode
runnning, where the "system" function was entirely disabled. But I
also read last week, that this "safe mode" is removed again in newer
PHP versions. Well, I'll have to see....

Anyway, you helped me back on track -- thank you very much, indeed.

Re: Building web applets with Haskell and PHP

noknok wrote:
Quoted text here. Click to load it

Just because safe mode is being removed doesn't mean you'll be able to
use system() or other functions.  Two entirely different things, and I
highly suspect they will be disabled even when your host upgrades, for
their own system protection.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline