Using jQuery With APE – change the background-color with PHP

A very quick post in regards to Matijah’s comment on Using jquery With APE. We can easily modify the colorChanger application so we can change the background via PHP. This could be extremely helpful in pushing UI changes to users clients, something I struggle to implement using plain PHP and JavaScript.

Demo

There is two code additions within colorChanger.js;

(inside init())

     this.onRaw('bgcolor', this.changeBgColor);

(new function)

        changeBgColor: function(color){
                if(typeof(color) != "string")
                        color = color.datas.value;

                return $("body").css("background-color", color);
        },

And that’s it, we’re good to go! We can call the update via; http://0.ape.ifc0nfig.com/?CONTROL&passw0rd&test&POSTMSG&bgcolor&pink&anticache using the libape-controller (make sure its loaded!). We can then call this URL via PHP with file_get_contents():

< ?php
$ape_server = 'http://0.ape.ifc0nfig.com';
file_get_contents($ape_server . '/?CONTROL&passw0rd&test&POSTMSG&bgcolor&pink&anticache');
echo 'Message sent!';
?>

BAM! The background has changed, try out the demo :)

Demo

  • Share/Bookmark

Related posts:

  1. Using jQuery with APE – an OOP approach with the DUI
  2. EsenAPE – send and receive SMS in real time using APE, jQuery, PHP and libape_controller
  3. Diving into APE modules and the JSF – creating topics for channels
  4. Using jQuery With APE
  5. Facebook Application – Call of Duty 5 Statistics

7 Responses to “Using jQuery With APE – change the background-color with PHP”

  1. Matijah  on September 3rd, 2009

    Hi Paul,

    thanx for the tutorial – it will sure be useful.

    However, when I make the call from php, the file_get_contents returns “ERR BAD_PASSWORD”.

    I double checked the password in libape-controller matches the password in the php.

    And I ran out of ideas…

    Reply

    • Paul Price  on September 3rd, 2009

      Hmm, I’m not too sure on that one.

      Try changing the password in bin/controller.conf to passw0rd (password=passw0rd), make sure there is no new lines after and then use my request string. The second parameter is the password. I believe it is case-sensitive.

      Reply

  2. Matijah  on September 3rd, 2009

    Thanx for mentioning the bin/controller.conf – I completley overlooked this file and was managing the password elsewhere.

    Now it works like a charm :)

    Reply

  3. iamdrich  on November 16th, 2009

    Here’s an example session of how this works in python instead of php:

    >>> import urllib
    >>> f = urllib.urlopen(‘http://0.ape.ape-test.local:6969/?CONTROL&testpwd&test&POSTMSG&bgcolor&pink&anticache’)
    >>> f.read()
    ‘OK POSTED’

    Reply

  4. davidynamic  on January 5th, 2010

    I was wondering why you use APE.Client.prototype

    Is that an old specification. Can it be used with the newest release.

    Reply


Leave a Reply