I created this piece of code to use Google Analytics Measurement Protocol instead of the google provided javascript, analytics.js in one of my page.
Recently I was playing with analytics javascript code, and I found that many times it will not collect data if something is blocking tracking codes (eg.: analytics.js) like when PrivDog is installed (amongs others).
The original idea is coming from here, but this is for wordpress.
http://www.stumiller.me/implementing-google-analytics-measurement-protocol-in-php-and-wordpress/
I modified the code to send data with sockets. (and without the wordpress functions library)
$gclid = $_GET['gclid'];
if (!empty($gclid)) {
setcookie("gclid", $gclid, time() + (10 * 365 * 24 * 60 * 60));
}
// Handle the parsing of the _ga cookie or setting it to a unique identifier
function gaParseCookie()
{
if (isset($_COOKIE['_ga'])) {
list($version, $domainDepth, $cid1, $cid2) = split('[\.]', $_COOKIE["_ga"], 4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1 . '.' . $cid2);
$cid = $contents['cid'];
} else {
$cid = gaGenUUID();
}
return $cid;
}
// Generate UUID v4 function - needed to generate a CID when one isn't available
function gaGenUUID()
{
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
// 16 bits for "time_mid"
mt_rand(0, 0xffff),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand(0, 0x0fff) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand(0, 0x3fff) | 0x8000,
// 48 bits for "node"
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
function gaBuildHit($method = null, $info = null)
{
global $gclid;
if ($method && $info) {
// Standard params
$v = 1;
$tid = "UA-XXXXXXX-XX"; // Put your own Analytics ID in here
$cid = gaParseCookie();
if (empty($gclid)) {
$gclid = $_COOKIE['gclid'];
}
// Register a PAGEVIEW
if ($method === 'pageview') {
// Send PageView hit
$data = array(
'v' => $v,
'tid' => $tid,
'cid' => $cid,
'gclid' => $gclid,
't' => 'pageview',
'dt' => $info['title'],
'dp' => $info['slug']
);
gaFireHit($data);
} // end pageview method
//
// Register an ECOMMERCE TRANSACTION (and an associated ITEM)
else if ($method === 'ecommerce') {
// Send Transaction hit
$data = array(
'v' => $v,
'tid' => $tid,
'cid' => $cid,
'gclid' => $gclid,
't' => 'transaction',
'ti' => $info['tid'], // Transaction ID
'ta' => 'SI',
'tr' => $info['price'], // transaction value (native currency)
'ts' => $info['shipping'], // transaction shipping (native currency)
'cu' => $info['cc'] // currency code
);
gaFireHit($data);
// Set up Item params
if ($info['info']->product_name) {
$in = urlencode($info['info']->product_name); // item name;
$ip = $tr;
$iq = 1;
$ic = urlencode($info['info']->product_id); // item SKU
$iv = urlencode('SI'); // Product Category - we use 'SI' in all cases, you may not want to
// Send Item hit
$data = array(
'v' => $v,
'tid' => $tid,
'cid' => $cid,
'gclid' => $gclid,
't' => 'item',
'ti' => $ti,
'in' => $in,
'ip' => $ip,
'iq' => $iq,
'ic' => $ic,
'iv' => $iv,
'cu' => $cu
);
gaFireHit($data);
}
} else if ($method === 'event') {
$data = array(
'v' => $v,
'tid' => $tid,
'cid' => $cid,
'gclid' => $gclid,
'ec' => $info['category'],
'ea' => $info['event'],
'el' => $info['label'],
'ev' => $info['value']
);
gaFireHit($data);
}
}
}
// See ttps://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
function gaFireHit($data = null)
{
if ($data) {
$url = 'https://ssl.google-analytics.com/collect';
$getString .= '?payload_data&';
$getString .= http_build_query($data);
$result = socketPost($url, $getString, $_SERVER['HTTP_USER_AGENT']);
return $result;
}
return false;
}
function socketPost($url, $post_string, $ua = null)
{
$parts = parse_url($url);
// workout port and open socket
$port = isset($parts['port']) ? $parts['port'] : 80;
$success = $fp = fsockopen($parts['host'], $port, $errno, $errstr, 30);
if ($fp) {
// create output string
$output = "POST " . $parts['path'] . " HTTP/1.1\r\n";
if (is_string($ua)) {
$output .= "User-Agent: " . $ua . "\r\n";
}
$output .= "Host: " . $parts['host'] . "\r\n";
$output .= "Content-Type: application/x-www-form-urlencoded\r\n";
$output .= "Content-Length: " . strlen($post_string) . "\r\n";
$output .= "Connection: Close\r\n\r\n";
$output .= isset($post_string) ? $post_string : '';
// send output to $url handle
$success = fwrite($fp, $output);
fclose($fp);
}
return $success ? true : false;
}
//examples:
//page hit
$data = array(
'title' => 'Page title',
'slug' => $_SERVER["REQUEST_URI"]
);
gaBuildHit('pageview', $data);
//ecommerce
$data = array(
'tid' => $order_id_in_merchant_system,
'cc' => 'AUD', // the currency code
'price' => $order_total, // the price
'shipping' => $order_shipping, // the shipping cost
'country' => 'AU' // the country ISO code
);
gaBuildHit('ecommerce', $data);
The code itself is working just fine. I put here for you to get the idea.
Question is, I dont really see the flow, how could an Adwords Click get tracked here. Like, if there is no _ga cookie set before (then gaParseCookie creates one), how could analytics connect the tracked event into eg.: an Analytics keyword the click coming from? Is that possible with Measurement Protocol?
Related
I want to integrate the payment partal without displaying the MasterCard interface to user the will only fill their information on my web
here
my portal
and not here
mastercard portal
I am trying to implement CommWeb on my PHP site using curl. It isn't working. I am getting following error message:
if ($_SERVER["REQUEST_METHOD"] == "GET") {
if (!isset($_GET['id']) || !isset($_GET['motif']) || !isset($_GET['code'])){
die("Invalid request");
}
$amount = 10000;
$id = 2;
$motif = 'save';
$action_code = 'ookkk';
$orderInfo = 'fhhsd'.$id;
$MerchTxnRef = $orderInfo.'-'.generateMerchTxnRef();
$accountData = array(
'merchant_id' => 'TESTID', // for test card
'access_code' => '77867878', // for test card
'secret' => 'TYUJHGFDFGHJ87654567GFDFGHGF' // for test card
);
$currency_str = "USD";
$mult = 100;
$queryData = array(
'vpc_AccessCode' => $accountData['access_code'],
'vpc_Merchant' => $accountData['merchant_id'],
'vpc_Amount' => 1000000, // Multiplying by 100 to convert to the smallest unit
'vpc_OrderInfo' => $orderInfo,
'vpc_MerchTxnRef' => $MerchTxnRef,
'vpc_Command' => 'pay',
'vpc_Currency' => $currency_str,
'vpc_Locale' => 'en',
'vpc_Version' => 2,
'vpc_ReturnURL' => ('http://theeventsfactory.biz/the_events_factory/logics/payment_return.php?id='.$id.'&motif='.$motif.'&code='.$action_code),
'vpc_SecureHashType' => 'SHA256',
'vpc_CardNum' => '5123456789012346',
'vpc_CardExp' => '0521',
'vpc_CardSecurityCode'=> '123'
);
// Add secure secret after hashing
// $queryData['vpc_SecureHash'] = generateSecureHash($accountData['secret'], $queryData);
// $migsUrl = 'https://migs.mastercard.com.au/vpcpay?'.http_build_query($queryData);
$ch = curl_init("https://migs.mastercard.com.au/vpcdps");
curl_setopt_array($ch, array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $queryData,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false
));
$response = curl_exec($ch);
print_r($response);
}
function generateMerchTxnRef() {
$txnRef = rand(9, 9999999999999999);
// Saved in the database associated with the order id
return $txnRef;
}
function generateSecureHash($secret, array $params) {
$secureHash = "";
// Sorting params first based on the keys
ksort($params);
foreach ($params as $key => $value)
{
// Check if key equals to vpc_SecureHash or vpc_SecureHashType to discard it
if(in_array($key, array('vpc_SecureHash', 'vpc_SecureHashType'))) continue;
// If key either starts with vpc_ or user_
if(substr( $key, 0, 4 ) === "vpc_" || substr($key, 0, 5) === "user_") {
$secureHash .= $key."=".$value."&";
}
}
// Remove the last `&` character from string
$secureHash = rtrim($secureHash, "&");
//
return strtoupper(hash_hmac('sha256', $secureHash, pack('H*', $secret)));
}
This is the response i am receiving
vpc_Amount=0&vpc_BatchNo=0&vpc_Locale=en&vpc_Message=Required+field+vpc_Merchant+was+not+present+in+the+request&vpc_TransactionNo=0&vpc_TxnResponseCode=7
How will i solve this problem
You need to convert the array to a url encoded string with http_build_query
after setting the queryData array, add
$queryData_string = http_build_query($queryData);
Then the curlpost would be set to that
CURLOPT_POSTFIELDS => $queryData_string,
I have been struggling to implement Google's Measurement Protocol on a Wordpress site.
Apache Server, using PHP 5.4.35.
What I want to do is get server-side visitor data loaded into Google Analytics. The site has huge discrepancies between server logs and GA data, and I'm hoping to get the two to (somewhat) match up.
I have taken the code published by Stu Miller on his website, and made some slight edits hoping to reflect my use case. I've added the following to my wp-includes/functions.php file:
require( ABSPATH . WPINC . '/http.php' );
require( ABSPATH . WPINC . '/class-http.php' );
require( ABSPATH . WPINC . '/general-template.php' );
// Handle the parsing of the _ga cookie or setting it to a unique identifier
// Generate UUID v4 function - needed to generate a CID when one isn't available
function gaGenUUID() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
function gaParseCookie() {
if (isset($_COOKIE['_ga'])) {
list($version,$domainDepth, $cid1, $cid2) = split('[\.]', $_COOKIE["_ga"],4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1.'.'.$cid2);
$cid = $contents['cid'];
}
else $cid = gaGenUUID();
return $cid;
}
function gaBuildHit( $method = null, $info = null ) {
if ( $method && $info) {
// Standard params
$v = 1;
$tid = "UA-xxxxxxx"; // Put your own Analytics ID in here
$cid = gaParseCookie();
// Register a PAGEVIEW
if ($method === 'pageview') {
// Send PageView hit
$data = array(
'v' => $v,
'tid' => $tid,
'cid' => $cid,
't' => 'pageview',
'dt' => $info['title'],
'dp' => $info['slug']
);
gaFireHit($data);
} // end pageview method
// Register an ECOMMERCE TRANSACTION (and an associated ITEM)
else if ($method === 'ecommerce') {
// Set up Transaction params
$ti = uniqid(); // Transaction ID
$ta = 'SI';
$tr = $info['price']; // transaction value (native currency)
$cu = $info['cc']; // currency code
// Send Transaction hit
$data = array(
'v' => $v,
'tid' => $tid,
'cid' => $cid,
't' => 'transaction',
'ti' => $ti,
'ta' => $ta,
'tr' => $tr,
'cu' => $cu
);
gaFireHit($data);
// Set up Item params
$in = urlencode($info['info']->product_name); // item name;
$ip = $tr;
$iq = 1;
$ic = urlencode($info['info']->product_id); // item SKU
$iv = urlencode('SI'); // Product Category - we use 'SI' in all cases, you may not want to
// Send Item hit
$data = array(
'v' => $v,
'tid' => $tid,
'cid' => $cid,
't' => 'item',
'ti' => $ti,
'in' => $in,
'ip' => $ip,
'iq' => $iq,
'ic' => $ic,
'iv' => $iv,
'cu' => $cu
);
gaFireHit($data);
} // end ecommerce method
}
}
global $post;
$data = array(
// Get the queried object and sanitize it
'title' => $title = $post->post_title,
'slug' => $slug = $post->post_name
);
gaBuildHit( 'pageview', $data);
// See https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
function gaFireHit( $data = null ) {
if ( $data ) {
$getString = 'https://ssl.google-analytics.com/collect';
$getString .= '?payload_data&';
$getString .= http_build_query($data);
$result = wp_remote_get( $getString );
#$sendlog = error_log($getString, 1, "ME#EMAIL.COM"); // comment this in and change your email to get an log sent to your email
return $result;
}
return false;
}
I have received several errors along the way, which started with the wp_remote_get() function being not defined, which resulted in my including the:
require( ABSPATH . WPINC . '/http.php' );
This inclusion moved up the error list to WP_Http() class not found, which resulted in my inclusion of:
require( ABSPATH . WPINC . '/class-http.php' );
... and so on. I don't quite remember the error which prompted my inclusion of:
require( ABSPATH . WPINC . '/general-template.php' );
I believe it was a PHP Fatal error: Call to undefined function get_bloginfo().
Anyway, I think I'm doing includes wrong. The latest fatal error is: Fatal error: Call to undefined function home_url() in /home/user/public_html/domain/wp-includes/general-template.php on line 658
I looked up the Wordpress Codex a bit and it also seems like the wp_remote_safe_post() would have been the better option, with Google recommending POST instead of GET due to the restricted payload on GET.
Unfortunately I lack the experience to make sense of how the code is supposed to be used, I had been hoping the initial code would be good enough to make happen, with maybe some tweaks.
Am I doing something wrong with the includes? Or has wordpress 4.6.1 moved so far ahead that all of this is deprecated? Or maybe I'm using the wrong functions.php file?
I have a and Array which looks like this:
$sms = array(
'from' => 'DummyFrom',
'to' => '+46709751949',
'message' => 'Hello hello!'
);
echo sendSMS ($sms) . "\n";
what i'm trying to do is to put this array within a foreach loop so it can be executed multiple time (based on the given times from mysql database). to explain it better, I did something like this:
if (is_array($g_numbers)) {
foreach ($g_numbers as $number) {
$sms = array(
'from' => 'DummyFrom',
'to' => "" . $number . "",
'message' => 'Hello hello!'
);
echo sendSMS($sms) . "\n";
}
}
but that is wrong and its stops the PHP page to execute properly without any errors!
Could someone please advise on this issue?
My full code :
<?php
$people = array();
$sql = "SELECT id, g_name, numbers FROM groups WHERE g_name='$groups'";
$query = mysqli_query($db_conx, $sql);
$productCount = mysqli_num_rows($query);
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$g_id = $row['id'];
$g_name = $row['g_name'];
$g_numbers = $row['numbers'];
$people[$g_numbers] = $g_numbers;
}
?>
<?
// Example to send SMS using the 46elks service
// Change $username, $password and the mobile number to send to
function sendSMS($sms)
{
// Set your 46elks API username and API password here
// You can find them at https://dashboard.46elks.com/
$username = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$password = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => "Authorization: Basic " . base64_encode($username . ':' . $password) . "\r\n" . "Content-type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query($sms),
'timeout' => 10
)
));
$response = file_get_contents('https://api.46elks.com/a1/SMS', false, $context);
if (!strstr($http_response_header[0], "200 OK"))
return $http_response_header[0];
return $response;
}
if (is_array($g_numbers)) {
foreach ($g_numbers as $number) {
$sms = array(
'from' => 'DummyFrom',
/* Can be up to 11 alphanumeric characters */
'to' => "" . $number . "",
/* The mobile number you want to send to */
'message' => 'Hello hello!'
);
echo sendSMS($sms) . "\n";
}
}
?>
This will work because tables values are stored in $people:
if (is_array($people)) {
foreach ($people as $number) {
$sms = array(
'from' => 'DummyFrom',
/* Can be up to 11 alphanumeric characters */
'to' => "" . $number . "",
/* The mobile number you want to send to */
'message' => 'Hello hello!'
);
echo sendSMS($sms) . "\n";
}
}
How to track the movement of the user between the two domains?
scheme:
1) the user clicks the button in doman-exemple1.com and go out from doman-exemple1.com and comes to doman-exemple2.com
login
2) doman-exemple2.com executed only on the server (that is not possible to use javascript)
<?php
// executed something codes... ;
// go with result to doman-exemple1.com
header('Location: http://doman-exemple1.com/?good='.$code);
?>
3) user returned to the http://doman-exemple1.com/?good=t45ygsw45t4
I need that google analytics understand that this same user and it not different users
This works:
https://support.google.com/analytics/answer/1034342?hl=en
But I cannot use thit becouse doman-exemple2.com executed only PHP and cannot use javascript
please help how to do this without javascript and only with PHP
P.S.
I read this: https://github.com/thomasbachem/php-ga but not understand if i can use this in my situations
If you are using Universal Analytics of GA, then have a look at the Measurement Protocol.
https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
That can allow you to track through PHP only, and by using the same cid you can continue to track (using the same profile) the session.
thenx for Marcel Dumont
code get from this example: http://www.stumiller.me/implementing-google-analytics-measurement-protocol-in-php-and-wordpress/
doman-exemple1.com:
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
//https://support.google.com/analytics/answer/1034342?hl=uk
//https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain
ga('create', 'UA-33396333-20', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['doman-exemple2.com'] );
ga('send', 'pageview');
</script>
doman-exemple2.com:
<?php
if (isset($_GET["_ga"])) {
setcookie('_ga_my', $_GET["_ga"],time()+3600*24*24);
list($version,$domainDepth, $cid1, $cid2) = split('[\.]', $_GET["_ga"],4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1.'.'.$cid2);
$cid = $contents['cid'];
$ga = "GA1.2.".$cid;
setcookie('_ga', $ga,time()+3600*24*24);
}
function gaParseCookie() {
if (isset($_COOKIE['_ga'])) {
list($version,$domainDepth, $cid1, $cid2) = split('[\.]', $_COOKIE["_ga"],4);
$contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1.'.'.$cid2);
$cid = $contents['cid'];
}
else $cid = gaGenUUID();
return $cid;
}
// Generate UUID v4 function - needed to generate a CID when one isn't available
function gaGenUUID() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
mt_rand( 0, 0x0fff ) | 0x4000,
// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
mt_rand( 0, 0x3fff ) | 0x8000,
// 48 bits for "node"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
);
}
//echo gaParseCookie();
function gaBuildHit( $method = null, $info = null ) {
if ( $method && $info) {
// Standard params
$v = 1;
$tid = "UA-33396333-20"; // Put your own Analytics ID in here
$cid = gaParseCookie();
// Register a PAGEVIEW
if ($method === 'pageview') {
// Send PageView hit
$data = array(
'v' => $v,
'tid' => $tid,
'cid' => $cid,
't' => 'pageview',
'dt' => $info['title'],
'dp' => $info['slug']
);
gaFireHit($data);
} // end pageview method
}
}
// See https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
function gaFireHit( $data = null ) {
if ( $data ) {
$getString = 'https://ssl.google-analytics.com/collect';
$getString .= '?payload_data&';
$getString .= http_build_query($data);
$result = file_get_contents( $getString );
#$sendlog = error_log($getString, 1, "ME#EMAIL.COM"); // comment this in and change your email to get an log sent to your email
return $result;
}
return false;
}
$data = array(
'title' => 'Login doman-exemple2.com',
'slug' => 'doman-exemple2.com'
);
gaBuildHit( 'pageview', $data);
$secrret="111";
if (isset($_COOKIE['_ga_my'])) {
$gogl='&_ga='.$_COOKIE['_ga_my'];
header('Location: https://doman-exemple1.com/mass-add-email?utm_source=good&secret='.$secrret.'&utm_medium=good&utm_campaign=good'.$gogl);
} else {
header('Location: https://doman-exemple1.com/mass-add-email?utm_source=good&secret='.$secrret.'&utm_medium=good&utm_campaign=good');
}
exit();
?>
I'm working on some Database functions and, for some reason, I made two functions to make simple inserts/selects with arrays passed as arguments to a php function. The problem starts here.
// basic database functions, to aid the development :D
static public function Insert($table, $items = array())
{
if(is_array($items) == false)
{
return false;
}
$header = 'INSERT INTO ' . $table . '(';
$values = 'VALUES(';
$count = count($items) - 1;
$cur = 0;
foreach($items as $key => $value)
{
$num = is_numeric($value);
$header .= $key . ($cur < $count) ? ', ' : ' ';
$values .= (($num) ? '' : '\'') . $value . (($num) ? '' : '\'') . (($cur < $count) ? ', ' : '');
$cur ++;
}
$header .= ')';
$values .= ')';
self::Query($header . $values);
}
$pair = array('id' => null,
'name' => Database::EscapeString((string)$xml->ID),
'avatar_url' => Database::EscapeString((string)$xml->Avatar),
'personal_msg' => Database::EscapeString((string)$xml->AboutMe),
'level' => (int)$xml->Level,
'progress' => (int)$xml->Progress,
'trophies_total' => (int)$xml->Trophies->Total,
'trophies_platinum' => (int)$xml->Trophies->Platinum,
'trophies_gold' => (int)$xml->Trophies->Gold,
'trophies_silver' => (int)$xml->Trophies->Silver,
'trophies_bronze' => (int)$xml->Trophies->Bronze,
'country' => Database::EscapeString((string)$xml->Country->Culture),
'is_plus' => (string)$xml->Plus,
'points' => (int)$xml->LevelData->Points,
'floor' => (int)$xml->LevelData->Floor,
'ceiling' => (int)$xml->LevelData->Ceiling,
'game_completion' => (double)$xml->GameCompletion,
'background_color' => ((int)$xml->Background->R << 16) | ((int)$xml->Background->G << 8) | ((int)$xml->Background->B),
'jid' => (string)$xml->jid
);
Insert('profiles', $pair);
The data that the query contains is not correct:
INSERT INTO profiles(, , , , , , , , , , , , , , , , , , , )VALUES('', 'AlmamuPP', 'http://static-resource.np.community.playstation.net/avatar/3RD/30004.png', 'EVE Online & DUST fan', 2, 17, 12, 0, 0, 6, 6, 'ES', 'false', 270, 200, 600, 12.5, 458759, 'AlmamuPP#a4.es.np.playstation.net')
As you may notice, it just ignores all the keys in the dictionary, but the funny fact is that if I add
echo $key;
in the foreach the keys are printed as they should... Any idea about what could be hapening there and a way to fix it?
You are missing parenthesis:
$header .= $key . (($cur < $count) ? ', ' : ' ');
Like this it will work.