[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Demexp-dev] New code for cookie

From: David MENTRE
Subject: Re: [Demexp-dev] New code for cookie
Date: Sat, 22 Sep 2007 14:49:14 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)

Hello Diogene,

Diogene Laerce <address@hidden> writes:

> I think I did some progress but I still not find any demexp cookie on my
> machine ??

In fact, this was only an issue related to the PHP encoding of the
response. :-) Here is the code that works on my machine:

------ start of php code -------
// One needs XML-RPC library to run
// this code.
include 'xmlrpc-2.2/lib/';  // <-- for my own setting!! Keep yours.

// Object to represent the server
$server = new

// mode debug

// Send a message to the server.
$login  =       new xmlrpcval("root", "string");
$passwd =       new xmlrpcval("demexp", "string");

$message = new xmlrpcmsg("login", array($login, $passwd));

$result = $server->send($message);

// Process the response.
if (!$result)
     print "<p>Could not connect to HTTP server.</p>";
elseif ($result->faultCode())
     print "<p>XML-RPC Fault #" . $result->faultCode() . ": " .
        $cookie = $result->value()->scalarVal(); // <-- Here is the trick!!
        print "<PRE>\nThe cookie for this session is '". $cookie . "'\n</PRE>";
------ end of php code -------

Some explanations:

 * the send() call on `xmlrpcmsg' object returns a `xmlrpcresp'
   object. See ;

 * the value() method on a `xmlrpcresp' object returns an `xmlrpcval'
   object. See ;

 * the scalarVal() method returns the scalar value stored in an
   `xmlrpcval' object. See .

Please notice that I *know* that the returned value is a scalar. This is
not always the case and you should use proper `xmlrpcval' methods
(scalarVal(), arrayMem(), arraySize(), structMem(), ...) to parse the
returned value.

In your case, I would build a small library that implements
PHP functions to do:

 1. login(), goodbye();

 2. max_question_id(), question_info();

 3. other methods on a need by need basis.

With that you should be able to list the question details.

Please note that it is quite important to call a goodbye() for each
login() call, otherwise you keep opened sessions on the
server. Typically you would have a call sequence like:







I hope I'm clear. Don't hesitate to ask further questions.

Have fun! ;-)

PS: An example of use of above code:

HTTP/1.1 200 OK
Date: Sat, 22 Sep 2007 12:44:24 GMT
Server: Apache/1.3.33 (Unix) PHP/4.3.11 mod_perl/1.29
Content-Length: 129
Connection: close
Content-Type: text/xml

<?xml version='1.0'?>


HEADER: date: Sat, 22 Sep 2007 12:44:24 GMT
HEADER: server: Apache/1.3.33 (Unix) PHP/4.3.11 mod_perl/1.29
HEADER: content-length: 129
HEADER: connection: close
HEADER: content-type: text/xml

   'me' => 
  array (
    'int' => 759732849,
   'mytype' => 1,
   '_php_class' => NULL,

The cookie for this session is '759732849'

GPG/PGP key: A3AD7A2A David MENTRE <address@hidden>
 5996 CC46 4612 9CA4 3562  D7AC 6C67 9E96 A3AD 7A2A

reply via email to

[Prev in Thread] Current Thread [Next in Thread]