Processing communicate with PHP?

edited November 2013 in How To...

How can I give variables from Processing to PHP.I found only this useless tutorial (http://www.learningprocessing.com/tutorials/php/)

greetz Flozzel

Tagged:

Answers

  • Are you using Processing on the server side or on the client side?

  • You cannot use Processing on the server side, anyway.

    The simplest way is to use loadStrings() with URLs pointing to PHP code.

  • I would be very happy about an example. greetz Flozzel

  • Why couldn't one use Processing on the server side, in theory?

  • Server side usually means command-line, an command-line usually means no possibility of an opengl window.

  • An example anybody? I´m a little bit confused with the loadStrings() function. I need a way to send values from Processing to php and later the other way back. greetz

  • edited November 2013 Answer ✓

    Example:

    Processing file or js:

            String s="Hello";
            println(s); //displays "Hello"
            String new=loadStrings("http://"+"mywebsite.com/index.php?value="+s);
            println(new); // should give you "Hello World!"
    

    PHP File on server:

      <?
      $myPHPValue=isset($_GET['value'])?$_GET['value']:"";
    
      echo $myPHPValue." World!";
    
      ?>
    

    Or, just play with Ajax requests from your javascript:

    http://en.wikipedia.org/wiki/Ajax_(programming)

  • edited November 2013

    Thanks for the example, diyoyo. For the record, the value s might need to be URL-encoded (special chars).

    In the past, I even shown how to do a file upload (save image to server). That's what the PostToWeb library does.

  • Thanks goes to diyoyo ^^ This is exactly what I searched for. greetz Flozzel

Sign In or Register to comment.