How to print all HTTP headers with PHP
PHP posted over 2 years ago by christian
1 <ul> 2 <?php 3 foreach($_SERVER as $h=>$v) 4 if(ereg('HTTP_(.+)',$h,$hp)) 5 echo "<li>$h = $v</li>\n"; 6 header('Content-type: text/html'); 7 ?> 8 </ul>
How to add logging to CakePHP applications
PHP posted over 2 years ago by christian
Note that Pear’s Logging package is a lot more flexible, so I recommend you use that instead of CakePHP’s built-in logging.
Use this code to add a debug message to the CakePHP debug log:
1 $this->log("Upload action accessed", LOG_DEBUG);
Note that using something other than LOG _DEBUG will log the message as an error.
Run the code once and you should be able to see the message in $CAKE_APP/tmp/logs/debug.log.
PHP XML-RPC example using Pear's XML_RPC package
PHP posted over 2 years ago by christian
First you need to install XML _RPC and VAR _DUMP:
Installing XML _RPC
1 pear install XML_RPC 2 pear install VAR_DUMP
Example XML -RPC client
Note this code hasn’t been tested, so may contain errors.
Anyway, VAR _DUMP is great for debugging…
1 <?php 2 require_once("XML/RPC.php"); 3 require_once('Var_Dump.php'); 4 5 Var_Dump::displayInit(array('display_mode' => 'HTML4_Text'), array('mode' => 'normal','offset' => 4)); 6 7 $host = "xxx.com"; 8 $uri = "/xxx/xmlrpc"; 9 10 $function = "eat"; 11 $parameters = array( 12 new XML_RPC_Value("a"), 13 new XML_RPC_Value(0), 14 new XML_RPC_Value(10), 15 new XML_RPC_Value("b") 16 ); 17 18 $message = new XML_RPC_Message($function, $parameters); 19 20 $client = new XML_RPC_Client($uri, $host, 80); 21 $client->setDebug(1); 22 $client->proxy = "127.0.0.1"; 23 24 $result = $client->send($message); 25 26 if (!$result) { 27 echo 'Communication error: '.$client->errstr; 28 Var_Dump::display($client); 29 exit; 30 } 31 32 if($result->faultCode()) 33 { 34 echo "** ERROR **n"; 35 echo 'Fault Code: ' . $result->faultCode() . "n"; 36 echo 'Fault Reason: ' . $result->faultString() . "n"; 37 exit; 38 } 39 40 echo "<pre>".htmlentities($message->serialize()). "</pre>"; 41 42 Var_Dump::display($result); 43 44 $val = $result->value(); 45 $ticket = $val->scalarval(); 46 47 echo $ticket; 48 ?> 49
Data types
struct
1 $user_params = array( 2 'username' => new XML_RPC_Value(".."), 3 'email' => new XML_RPC_Value("..."), 4 'time' => new XML_RPC_Value(gmdate("Ymd\TH:i:s"), 'dateTime.iso8601') 5 ); 6 7 $rpc_param = new XML_RPC_Value($user_params, 'struct')
dateTime.iso8601
1 'time' => new XML_RPC_Value(gmdate("Ymd\TH:i:s"), 'dateTime.iso8601')