Archive for December, 2012

Consuming a Datasnap Server with PHP passing JSONObject as parameter

I have a Datasnap Server and a have a method named :

function TServerMethodsMain.AddCity( ACity : TJSONObject ) : Boolean ;

I did small php code below to invoke this method.


class city
   public $id;
   public $description;
   public $uf;          

$objcity = new city ;

$objcity -> id          = 1         ;
$objcity -> description = 'MY CITY' ;
$objcity -> uf          = 'XX'      ;

$url  = '' ;
$url .= json_encode( $objcity ) ;

$page = file($url) ;  

$show = json_decode($page[0]);

echo '<pre>';

print_r ($show);

echo '</pre>';


I got this error message from browser (Firefox or IE) :

CITY”,”uf”:”XX”}) [function.file]:
failed to open stream: HTTP request
failed! HTTP/1.1 500 Internal Server
Error in
C:\xampp\htdocs\json-php\index.php on
line 19

Well, I have others methods that works fine with this php code, but only if I pass as parametrer Primitive Types : String, Integer…

I did a debug and see that problem happens at moment I need to convert parameter JSONObject into Object ( unMarshalll ). When I invoke this method by Client Delphi Win32 it works fine !

Does anybody knows anything about the problem ?

Thanks !

Sending signals to process via php

I am trying to send a kill -10 (SIGUSER1) to a process ID by using a button in a webpage, I have tried different ways to send the signal while passing the PHP variable (which holds the PID) to shell. Below is what I have:

$next = posix_kill($pid3, 10);

Right now, this is giving me the below error:

PHP Warning:  posix_kill() expects parameter 1 to be long, 
              string given in /var/www/parse2.php on line 15

Please advise

PHP self encoding algorithm

I’ve been using base64 encoding for a while & it isn’t secure because some decoders can easily identify it.

So is it a good idea to develop my own mechanism to protect data or make my encryption algorithm, if yes then how does self made encryption code look like?

Drupal not loading PHP on WAMP

I am working on a local dev environment for a Drupal site we are building. I am having trouble at one last step, and that is getting PHP in Drupal to execute properly. As you see below, when I view source on the localhost page being executed in PHP the HTML markup contains PHP code that should be executed server side first. I have confirmed the DB is connected fine, and this site runs fine on our production server. How can I fix this issue?

<!DOCTYPE html>
<html xmlns="" xml:lang="<?= $language->language; ?>" lang="<?= $language->language; ?>">
<head profile="<?= $grddl_profile; ?>">
    <?= $head; ?>
    <title><?= $head_title; ?></title>
    <?= $styles; ?>
<body class="<?= $classes; ?>" <?= $attributes;?>>

<?= $page_top; ?>
<?= $page; ?>
<?= $page_bottom; ?>

<?= $scripts; ?>

Passing a value into a mysql update form / modal window (Twitter Bootstrap)

I am building a site where users can create and edit database entries. Currently users can click on an edit link that passes a $_GET value on to the next page. A mysql query grabs the $_GET value and displays a edit form with the appropriate entry data filled in.


How can I produce this result with a modal window instead of directing the users to another page?

Also, here are links to the relevant code:

How do I update phpunit?

I have already tried everything, including and all possible channel upgrade and clear cache commands. But still:

$ sudo pear install -a -f phpunit/PHPUnit
downloading PHPUnit-3.6.12.tgz ...
Starting to download PHPUnit-3.6.12.tgz (120,240 bytes)
..........................done: 120,240 bytes
install ok: channel://


$ pear list-upgrades
Channel No upgrades available Available Upgrades (stable):
Channel         Package            Local           Remote          Size PHPUnit            3.6.12 (stable) 3.7.10 (stable) 115kB PHPUnit_MockObject 1.1.1 (stable)  1.2.2 (stable)  19.9kB PHPUnit_Selenium   1.2.8 (stable)  1.2.11 (stable) 38kB PHP_CodeCoverage   1.1.4 (stable)  1.2.7 (stable)  155kB PHP_TokenStream    1.1.4 (stable)  1.1.5 (stable)  9.7kB Text_Template      1.1.3 (stable)  1.1.4 (stable)  3.6kB


There will be 100 points bounty for a person who will hint what can cause PEAR not be able to upgrade phpunit to the latest possible (using PEAR).

eBay API to download user listing

I am new to the eBay API and currently developing in PHP, I have managed to use GetItem to import details of an order based on the Item ID to my website’s database. But What I want to do now is to link a users account to my website and import their listings to my database. I have put the code I used for GetItem (below) but now I am stuck and I don’t know what to use, GetAccount, GetUser or GetSellerList to:

First: have my user redirected from my website to eBay to authorize my application to access his/her listings.

Second: Import that listing (an echo would be enough for now) to my website.

This is my code for GetUser:


        //Get the ItemID inputted
        $id = $_POST['Id'];

        //SiteID must also be set in the Request's XML
        //SiteID = 0  (US) - UK = 3, Canada = 2, Australia = 15, ....
        //SiteID Indicates the eBay site to associate the call with
        $siteID = 101;
        //the call being made:
        $verb = 'GetItem';

        ///Build the request Xml string
        $requestXmlBody = '<?xml version="1.0" encoding="utf-8" ?>';
        $requestXmlBody .= '<GetItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
        $requestXmlBody .= "<RequesterCredentials><eBayAuthToken>$userToken</eBayAuthToken></RequesterCredentials>";;
        $requestXmlBody .= "<ItemID>$id</ItemID>";
        $requestXmlBody .= '</GetItemRequest>';

        //Create a new eBay session with all details pulled in from included keys.php
        $session = new eBaySession($userToken, $devID, $appID, $certID, $serverUrl, $compatabilityLevel, $siteID, $verb);

        //send the request and get response
        $responseXml = $session->sendHttpRequest($requestXmlBody);
        if(stristr($responseXml, 'HTTP 404') || $responseXml == '')
            die('<P>Error sending request');

        //Xml string is parsed and creates a DOM Document object
        $responseDoc = new DomDocument();

        //get any error nodes
        $errors = $responseDoc->getElementsByTagName('Errors');

        //if there are error nodes
        if($errors->length > 0)
            echo '<P><B>eBay returned the following error(s):</B>';
            //display each error
            //Get error code, ShortMesaage and LongMessage
            $code = $errors->item(0)->getElementsByTagName('ErrorCode');
            $shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
            $longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
            //Display code and shortmessage
            echo '<P>', $code->item(0)->nodeValue, ' : ', str_replace(">", "&gt;", str_replace("<", "&lt;", $shortMsg->item(0)->nodeValue));
            //if there is a long message (ie ErrorLevel=1), display it
            if(count($longMsg) > 0)
                echo '<BR>', str_replace(">", "&gt;", str_replace("<", "&lt;", $longMsg->item(0)->nodeValue));


        else //no errors
            //get the nodes needed
            $titleNode = $responseDoc->getElementsByTagName('Title');
            $primaryCategoryNode = $responseDoc->getElementsByTagName('PrimaryCategory');
            $categoryNode = $primaryCategoryNode->item(0)->getElementsByTagName('CategoryName');
            $listingDetailsNode = $responseDoc->getElementsByTagName('ListingDetails');
            $startedNode = $listingDetailsNode->item(0)->getElementsByTagName('StartTime');
            $endsNode = $listingDetailsNode->item(0)->getElementsByTagName('EndTime');

            $ShippingPackageDetailsNode = $responseDoc->getElementsByTagName('ShippingPackageDetails');
            if ($ShippingPackageDetailsNode->length > 0) {
                $packageDepthNode = $ShippingPackageDetailsNode->item(0)->getElementsByTagName('PackageDepth');
                $DepthUnit = $packageDepthNode->item(0)->getAttribute('unit');
                $packageLengthNode = $ShippingPackageDetailsNode->item(0)->getElementsByTagName('PackageLength');
                $LengthUnit = $packageLengthNode->item(0)->getAttribute('unit');
                $packageWidthNode = $ShippingPackageDetailsNode->item(0)->getElementsByTagName('PackageWidth');
                $WidthUnit = $packageWidthNode->item(0)->getAttribute('unit');

            $sellingStatusNode = $responseDoc->getElementsByTagName('SellingStatus');
            $currentPriceNode = $sellingStatusNode->item(0)->getElementsByTagName('CurrentPrice');
            $currency = $currentPriceNode->item(0)->getAttribute('currencyID');
            $startPriceNode = $responseDoc->getElementsByTagName('StartPrice');
            $buyItNowPriceNode = $responseDoc->getElementsByTagName('BuyItNowPrice');
            $bidCountNode = $sellingStatusNode->item(0)->getElementsByTagName('BidCount');

            $sellerNode = $responseDoc->getElementsByTagName('Seller');

            //Display the details
            echo '<P><B>', $titleNode->item(0)->nodeValue, " ($id)</B>";
            echo '<BR>Category: ', $categoryNode->item(0)->nodeValue;
            echo '<BR>Started: ', $startedNode->item(0)->nodeValue;
            echo '<BR>Ends: ', $endsNode->item(0)->nodeValue;

            if ($ShippingPackageDetailsNode->length > 0) {
                echo "<BR>Package Length: ", $packageLengthNode->item(0)->nodeValue, ' '.$LengthUnit.'';
                echo "<BR>Package Width: ", $packageWidthNode->item(0)->nodeValue, ' '.$WidthUnit.'';
                echo "<BR>Package Depth: ", $packageDepthNode->item(0)->nodeValue, ' '.$DepthUnit.'';

            echo "<P>Current Price: ", $currentPriceNode->item(0)->nodeValue, $currency;
            echo "<BR>Start Price: ", $startPriceNode->item(0)->nodeValue, $currency;
            echo "<BR>BuyItNow Price: ", $buyItNowPriceNode->item(0)->nodeValue, $currency;
            echo "<BR>Bid Count: ", $bidCountNode->item(0)->nodeValue;

            //Display seller detail if present
            if($sellerNode->length > 0)
                echo '<P><B>Seller</B>';
                $userIDNode = $sellerNode->item(0)->getElementsByTagName('UserID');
                $scoreNode = $sellerNode->item(0)->getElementsByTagName('FeedbackScore');
                $regDateNode = $sellerNode->item(0)->getElementsByTagName('RegistrationDate');

                echo '<BR>UserID: ', $userIDNode->item(0)->nodeValue;
                echo '<BR>Feedback Score: ', $scoreNode->item(0)->nodeValue;
                echo '<BR>Registration Date: ', $regDateNode->item(0)->nodeValue;

WordPress current_page_item with post titles and changing colors

I will have 4 posts on my website, and the following loop will list them across all the pages of a website as a vertical menu (only post titles will be shown in this menu). After one of these will be clicked, it will load up the post as a new web page. What I’d like to have is for the current active post title (menu item) to be highlighted (just like with any regular website menu when you’re on a certain page). What can I add to the code below to make this happen? (I would then like to modify the colors etc. through CSS.)

Current code I have:

    <?php $posts = get_posts( "category_name=name_of_menu&numberposts=4&orderby=date&order=ASC" ); foreach($posts as $post) : ?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php endforeach; ?>

A few notes: I currently have this loop inside my single.php file, meanwhile the info outputs in to a Page. Basically it works like this: Page loads up, on the left are 4 post titles in a vertical menu (kind of like a sidebar). When you click on one, a new page loads which will contain that particular post’s content.

I am familiar with HTML and CSS, but not WordPress, so whatever I’ve tried doing with HTML hasn’t work for me thus far.

I tried editing current_page_item, but the thing is that I have a horizontal menu at the top of the website as well, so what happens is that neither of them display active/current color. The top horizontal menu is main menu, and the vertical (that I’m trying to get colors to work with) is vertical (left side of the page).

carousel slider cell phone swipe effect

Basically this below link has a carousel slider for the android cellphone. I’m trying to create the same effect with my website.

enter image description here

I’m trying to create a website like this but with the user being able to swipe the screens to go to the next screen, instead of auto or buttons…

What type of free downloadable carousals are available online that causes this responce from the carousal when the user swipes a website on a cell phone screen. I can only find free ones that don’t have the swipe effect.

PHP search for website with specific words

I’m trying to monitor a new products page of a website with specific words. I already have a basic script that searches for a single word using file_get_contents(); however this is not effective.

Looking at the code they are in <td> tags within a <table>

How do I get PHP to search for the words no matter what order and get declaration they are in? e.g.

$searchTerm = "Orange Boots";


   <td>Boots (Red)</td>
   <td>boots (ORNAGE)</td>
   <td>Shirt (Green)</td>

Returns a match.

Sorry if its not clear, but I hope you understand
Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.