Page 1 of 1

Array ????

Posted: Thu Sep 27, 2007 5:54 am
by phpcoder
HI,
I got an array $orders. When I try to use print_r($orders) command I get the following output.

Array([order] => Array ( [id] => PERFRST200709262 [epochorder] => 1190815734 [datemonth] => 09 [dateday] => 26 [dateyear] => 2007 [sessionid] => z96apk44r3nmjfh62mwp4i98yk5r39km [status] => NS [paymethod] => protx_test [ordertotal] => 12.45 [recurtotal] => 0.00 [recurtotaleutax] => 0.00 [recurtotaleutaxrefund] => 0.00 [subtotal] => 9.95 [taxsptotal] => 0.00 [taxctotal] => 0.00 [eutaxrefundtotal] => 0.00 [custsaletotal] => 0.00 [disctotal] => 0.00 [shiptotal] => 2.50 [commtotal] => 0.00 [disccode] => [taxexemptnum] => [custsaledesc] => [fname] => Andy [lname] => Lewis [company] => [phone] => 07711383059 [fax] => [email] => sales@xhosa-dev.co.uk [addone] => 33 Leech [addtwo] => [city] => Ashton [stateprov] => Lancashire [country] => UK - England & Wales [postalcode] => OL6 8HH [rescom] => R [eutaxno] => [customone] => [customtwo] => [customthree] => [customfour] => [customfive] => [customsix] => [customseven] => [customeight] => [customnine] => [customten] => [postordaff] => 1 [postordinv] => 1 [postorddisc] => 1 [postordqb] => 0 [postordpt] => 0 [postordsage] => 0 [commentsint] => [commentsext] => [referrer] => http://www.perfumefirst.co.uk/khxc/admin.php [ipaddress] => 91.102.62.66 [proctoken] => [trackupstools] => [netbanxref] => ) [items] => Array ( [0] => Array ( [id] => PERFRST200709262-2pn058zz8242 [orderid] => PERFRST200709262 [epochorder] => 1190815734 [shipstatus] => P [shipmethod] => Second Class Recorded [itemname] => Star website test product 1 [itemnum] => WEBSTAR001 [itemid] => test [itemquan] => 1 [itemopts] => [ordertotal] => 9.95 [recurtotal] => 0.00 [fname] => Andy [lname] => Lewis [company] => [addone] => 33 Leech [addtwo] => [city] => Ashton [stateprov] => Lancashire [country] => UK - England & Wales [postalcode] => OL6 8HH [rescom] => R [cartdata] => Array ( [randid] => 2pn058zz8242 [id] => test [quantity] => 1 [name] => Star website test product 1 [number] => WEBSTAR001 [imgsm] => AGPAGPF0102502s.JPG [prodinv] => 1 [optdisp] => Array ( ) [optinv] => [dlfiles] => [delmethod] => C [sinshipinfo] => Array ( [customship] => Fahad [shipweight] => 0.4 [shiptype] => C ) [shipemail] => shipping@perfumefirst.co.uk [sinprodprice] => Array ( [type] => R [displayb] => £9.95 [actualb] => 9.95 [displayr] => [actualr] => [displaybx] => [actualbx] => [displaybeutax] => £0.00 [actualbeutax] => 0.00 [displayreutax] => [actualreutax] => [displaybxeutax] => [actualbxeutax] => ) [sinoptprice] => [sinaffcomm] => 0 [istaxsp] => 0 [istaxc] => H [subtotal] => 9.95 [subtotalrec] => 0 [subtotaleutax] => 0 [subtotalreceutax] => 0 [amttaxsp] => 0 [amttaxc] => 0 [amtship] => 0 [coshipinfo] => Array ( [sfname] => [slname] => [scompany] => [saddone] => [saddtwo] => [scity] => [sstateprov] => [scountry] => [spostalcode] => [srescom] => ) [url] => INTERNAL [addemtext] => [savetype] => CART ) ) ) [display] => Array ( [orderstatus] => Array ( [C] => Completed [NS] => Pending Shipment [P] => Pending Payment [PS] => Partially Shipped [X] => Cancelled ) [shipstatus] => Array ( [N] => Not Applicable [P] => Pending Shipment [S] => Shipped ) ) [custom] => Array ( [disccode] => Discount Code ) [gateway] => Array ( [id] => protx_test [name] => Protx - Payment Form [active] => 1 [urltype] => E [dispname] => Purchase using your credit or debit card [disporder] => 1 [fieldrc] => PROTXresp [fieldon] => PROTXtrans [fieldtotal] => Amount [validrc] => OK [refurlstr] => gbu0.php [transkey] => p5YvA4hZRbxTvaXc [userid] => perfume1st [postorder] => 1 [recursup] => 0 [incdisp] => globals('khxc.app'); $eol = $this->globals('khxc.eol'); $order = $this->globals('ecom.order_summary'); // +-- // | Printable form instructions. // +-- $instructions = "After verifying your order information and clicking the 'Continue' button, you will be directed to our online processing partner's secure site to enter your payment information. Once your payment information is entered and verified, you will be directed back to this web site for your order confirmation."; // +-- // | Create our relay URL. // +-- $url_relay = $this->globals('khxc.url_ssl') . '/relay/' . $app . '.php'; $url_bad = $url_relay . '?PROTXtrans=' . $order['order']['id'] . '&PROTXresp=FAILED'; $url_ok = $url_relay . '?PROTXtrans=' . $order['order']['id'] . '&PROTXresp=OK'; // +-- // | Set up the olpform array. // +-- $olpform = array('url' => 'https://ukvps.protx.com/vps2form/submit.asp', 'button' => 'Continue', 'fields' => array()); // +-- // | Create the Protx Form Hash Field. // +-- //** Build the crypt string plaintext ** $stuff = "VendorTxCode=" . $order['order']['id'] . "&"; $stuff .= "Amount=" . $order['order']['ordertotal'] . "&"; $stuff .= "Currency=" . $this->globals('khxc_settings.' . $app . '.basecurrency') . "&"; $stuff .= "Description=" . "Online Order" . "&"; $stuff .= "SuccessURL=" . $url_ok . "&"; $stuff .= "FailureURL=" . $url_bad . "&"; $stuff .= "CustomerEmail=" . $this->globals('khxc_user.id') . "&"; $stuff .= "VendorEmail=" . $this->globals('khxc_settings.' . $app . '.default_contact_email') . "&"; $stuff .= "CustomerName=" . $order['order']['fname'] . ' ' . $order['order']['lname'] . "&"; $stuff .= "BillingAddress=" . $order['order']['addone'] . ' ' . $order['order']['addtwo'] . ' ' . $order['order']['city'] . ' ' . $order['order']['stateprov'] . "&"; $stuff .= "BillingPostCode=" . $order['order']['postalcode'] . "&"; // new 2.22 fields if ($order['order']['phone']) { $stuff .= "ContactNumber=" . $order['order']['phone'] . "&"; } if ($order['order']['fax']) { $stuff .= "ContactFax=" . $order['order']['fax'] . "&"; } $stuff .= "AllowGiftAid=" . '0' . "&"; $stuff .= "ApplyAVSCV2=" . '0' . "&"; $stuff .= "Apply3DSecure=" . '0' ; // ** Encrypt the plaintext string for inclusion in the hidden field ** $crypt = base64Encode(SimpleXor($stuff,$order['gateway']['transkey'])); if ($this->debug) {$this->debugger("Protxform: Crypt '{$crypt}' Crypt String '{$stuff}'.");} // +-- // | Create the HIDDEN fields for the form. // +-- $olpform['fields']['HIDDEN'][] = array('name' => 'Vendor', 'value' => $order['gateway']['userid']); $olpform['fields']['HIDDEN'][] = array('name' => 'VPSProtocol', 'value' => '2.22'); $olpform['fields']['HIDDEN'][] = array('name' => 'TxType', 'value' => 'PAYMENT'); $olpform['fields']['HIDDEN'][] = array('name' => 'Crypt', 'value' => $crypt); // +-- // | Create the DISPLAY fields for the form. // +-- $olpform['fields']['DISPLAY'][] = array('type' => 'PAYFORMCONTINUE', 'params' => array('name' => 'ecom_continue', 'required' => 1, 'display' => 'Payment Information', 'desc' => $instructions, 'option' => 'Enter Payment Information')); // +-- // | Globalize the $olpform array and return. // +-- $this->globals('ecom.olpform',$olpform); //********************************************************************************* // ** Base 64 Encoding function ** // PHP does it natively but just for consistency and ease of maintenance, let's declare our own function function base64Encode($plain) { // Initialise output variable $output = ""; // Do encoding $output = base64_encode($plain); // Return the result return $output; } // ** Base 64 decoding function ** // PHP does it natively but just for consistency and ease of maintenance, let's declare our own function function base64Decode($scrambled) { // Initialise output variable $output = ""; // Fix plus to space conversion issue $scrambled = str_replace(" ","+",$scrambled); // Do encoding $output = base64_decode($scrambled); // Return the result return $output; } /* The SimpleXor encryption algorithm ** ** NOTE: This is a placeholder really. Future releases of VSP Form will use AES or TwoFish. Proper encryption ** ** This simple function and the Base64 will deter script kiddies and prevent the "View Source" type tampering ** ** It won't stop a half decent hacker though, but the most they could do is change the amount field to something ** ** else, so provided the vendor checks the reports and compares amounts, there is no harm done. It's still ** ** more secure than the other PSPs who don't both encrypting their forms at all */ function simpleXor($InString, $Key) { // Initialise key array $KeyList = array(); // Initialise out variable $output = ""; // Convert $Key into array of ASCII values for($i = 0; $i < strlen($Key); $i++){ $KeyList[$i] = ord(substr($Key, $i, 1)); } // Step through string a character at a time for($i = 0; $i < strlen($InString); $i++) { // Get ASCII code from string, get ASCII code from key (loop through with MOD), XOR the two, get the character from the result // % is MOD (modulus), ^ is XOR $output.= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)])); } // Return the result return $output; } ?> ) [download] => Array ( [username] => Username [password] => "–?Ùó ) ) ;


I need to extract few data from this array like ordernumet name address etc. please let me know how to do it. As this array look so cmplex so I dont no using normal way of accessing values is the right way.

Code: Select all

echo $order['[id'];

Posted: Thu Sep 27, 2007 6:04 am
by Hemlata
Hello,

Take view source of the page where you are printing this array, and there you can read the formatted array and then can get the required values by simply using the proper array key values.

Regards,

Posted: Thu Sep 27, 2007 8:13 am
by Zoxive

Code: Select all

print '<pre>'; print_r ($array); print '</pre>';
More Readable in browser.