Gigya User Object is Missing - php

I've just started using Gigya to allow users to connect to my site. I already have a login system so I just want to connect existing users to the Gigya service.
To do this I have called the "gigya.services.socialize.notifyLogin" function which returns a Gigya User object with the UID provided by my site. [fig 1]
Do I need to do anything with this User object, like add it to a cookie or is it just for reference.
The problem that Im having is on another page, I want to allow users to connect to their social media accounts. I use the "showAddConnectionsUI" function passing my api key, but the returned object does NOT have the User object in, although the documentation says it should. How do I get the users conenctions and the key information from this function. Do I need to send any additional information along with my api key. [fig 2]
I have spent several days reading the wiki, documentation and forum for advice but I am still stuck. Any help would be greatly appreciated. Thanks in advance, Ben
[fig 1]
<script type="text/javascript" src="http://cdn.gigya.com/js/socialize.js?apiKey=<?php echo $key; ?>"></script>
<script type="text/javascript">
var gigyaConf = { APIKey: "<?php echo $key; ?>", signIDs: "true" }
var signature = "<?php echo $signature; ?>";
var siteUID = "<?php echo $userId; ?>";
var timestamp = "<?php echo $timestamp; ?>";
var gigyaParams =
{
siteUID:siteUID,
timestamp:timestamp,
signature:signature,
callback:gigyaNotifyLoginCallback
};
gigya.services.socialize.notifyLogin(gigyaConf, gigyaParams);
function gigyaNotifyLoginCallback(eventObj) {
if ( eventObj.errorCode != 0 ) {
alert('Gigya Error: ' + eventObj.errorMessage);
}
}
</script>
[fig 2]
<script type="text/javascript" lang="javascript" src="http://cdn.gigya.com/JS/socialize.js?apikey=<?php echo $key; ?>"></script>
<script>
var conf = { APIKey: '<?php echo $key; ?>', signIDs: 'true' };
$(document).ready(function(){
gigya.services.socialize.getUserInfo(conf, { callback: renderUI });
gigya.services.socialize.addEventHandlers(conf,
{
onConnectionAdded: renderUI,
onConnectionRemoved: renderUI
});
});
</script>
<script>
function renderUI(res) {
if (res.user != null && res.user.isConnected) {
document.getElementById("name").innerHTML = res.user.nickname;
if (res.user.thumbnailURL.length > 0)
document.getElementById("photo").src = res.user.thumbnailURL;
else
document.getElementById("photo").src = "http://cdn.gigya.com/site/images/bsAPI/Placeholder.gif";
document.getElementById("profile").style.display = "block";
} else {
document.getElementById("profile").style.display = "none";
}
}
</script>
<div id="content">
<h5>Step 1: Connect</h5>
<div id="divConnect"></div>
<script type="text/javascript">
gigya.services.socialize.showAddConnectionsUI(conf, {
height:65,
width:175,
showTermsLink:false,
hideGigyaLink:true,
useHTML:true,
containerID: "divConnect"
});
</script>
<br />
<h5>Step 2: See User Info</h5><br />
<div id=profile style="display:none;">
<img id="photo" src="" width="60" />
<br />
<span id="name" ></span>
</div>
</div>
Any help, advice, code snippits that would help will be greatly appreciated

Re: your first question, not required to do anything special with the Gigya User object. It's for your reference.
Re: your code, I can't tell if you're using JQuery but I was getting an error with your $(document).ready function. I modified your code slightly by adding body onLoad and everything worked. This assumes you have connected with a provider. Here's my code... hope it helps:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" lang="javascript" src="http://cdn.gigya.com/JS/socialize.js?apikey=<?php echo $key; ?>"></script>
<script>
var conf = { APIKey: '<?php echo $key; ?>', signIDs: 'true' };
function onLoad() {
gigya.services.socialize.getUserInfo(conf, { callback: renderUI });
gigya.services.socialize.addEventHandlers(conf,
{
onConnectionAdded: renderUI,
onConnectionRemoved: renderUI
});
}
</script>
<script>
function renderUI(res) {
if (res.user != null && res.user.isConnected) {
document.getElementById("name").innerHTML = res.user.nickname;
if (res.user.thumbnailURL.length > 0)
document.getElementById("photo").src = res.user.thumbnailURL;
else
document.getElementById("photo").src = "http://cdn.gigya.com/site/images/bsAPI/Placeholder.gif";
document.getElementById("profile").style.display = "block";
} else {
document.getElementById("profile").style.display = "none";
}
}
</script>
<body onload="onLoad()">
<div id="content">
<h5>Step 1: Connect</h5>
<div id="divConnect"></div>
<script type="text/javascript">
gigya.services.socialize.showAddConnectionsUI(conf, {
height:65,
width:175,
showTermsLink:false,
hideGigyaLink:true,
useHTML:true,
containerID: "divConnect"
});
</script>
<br />
<h5>Step 2: See User Info</h5><br />
<div id=profile style="display:none;">
<img id="photo" src="" width="60" />
<br />
<span id="name" ></span>
</div>
</div>
</body>
</html>

Related

Can not deserialize instance of String out of START_OBJECT token

I've gone through the other answers to this question, but no one seems to be able to apply it universally. Other questions just go unanswered.
Obviously, I'm getting "Can not deserialize instance of String out of START_OBJECT token." in my console. I believe it happens when I attempt to stringify(response) from my websocketdata.
Here is the code.
<?php /**
* The Header for our theme.
*
* Displays all of the <head> section and everything up till <div id="main">
*
*/ ?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<script type="text/javascript"
src='http://martialparks.com/wp-content/themes/js/gamesparks-rt.js'></script>
<script type='text/javascript' src='http://martialparks.com/wp-content/themes/js/gamesparks.js'></script>
<script type='text/javascript'
src='http://martialparks.com/wp-content/themes/js/gamesparks-functions.js'></script>
<script type='text/javascript' src='http://martialparks.com/wp-content/themes/js/hmac-sha256.js'></script>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php
wp_head();
?>
</head>
<body <?php body_class() ?>>
<body onload="init()">
<!--Start Header Wrapper-->
<div class="header_wrapper">
<div class="header">
<!--Start Container-->
<div class="container_24">
<div class="grid_24">
<div class="logo"> <a href="<?php echo esc_url(home_url()); ?>"><img src="<?php if (business_directory_get_option('business_directory_logo') != '') { ?><?php echo esc_url(business_directory_get_option('business_directory_logo')); ?><?php
} else {
echo esc_url(get_template_directory_uri() . '/images/logo.png');
}
?>" alt="<?php bloginfo('name'); ?>" /></a></div>
</div>
<div class="clear"></div>
</div>
<!--End Container-->
<div class="clear"></div>
</div>
<div class="clear"></div>
<!--Start Menu Wrapper-->
<div class="menu_wrapper">
<div class="top_arc"></div>
<div class="menu-container">
<div class="container_24">
<div class="grid_24">
<?php business_directory_nav(); ?>
</div>
</div>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="bottom_arc"></div>
</div>
<!--End Container-->
<div class="clear"></div>
</div>
<!--End Header Wrapper-->
<div class="clear"></div>
<div class="wrapper">
<!--Start Container-->
<div class="container_24">
<div class="grid_24">
<br/>
<br/>
<br/>
<input id="apiKey" type="hidden" value="A319082inSk2"/>
<input id="apiSecret" type="hidden" value="BNuYLYZAoDZDZyh1F7tbR8BMTiqeJbWt"/>
<label for="apiCredential">Api Credential</label><input id="apiCredential"/>
<label for="username">User Name</label><input id="username"/>
<label for="password">Password</label><input id="password"/>
<button onClick='gamesparks.registrationRequest("testuser", "testuser", "testuser", registerResponse)'>Register</button>
<button onClick='gamesparks.authenticationRequest(username, password, loginResponse)'>Login</button>
<button onClick='gamesparks.accountDetailsRequest(accountDetailsResponse)'>Account Details</button>
<button onClick='customEvent()'>Custom Event</button>
<button onClick='testRT()'>Test RT</button>
<i>Special thanks to the awesome team at GameSparks!</i>
<div id="messages"></div>
<br/>
<br/>
User Name
<div id="displayName" style="color: blue;"></div>
Coins
<div id="Coins" style="color: red;"></div>
Exp
<div id="Exp" style="color: green;"></div>
Leader Points
<div id="LeadP" style="color: darkgreen;"></div>
Hero Points
<div id="HeroP" style="color: purple;"></div>
<style>
#map {
height: 400px;
width: 100%;
}
</style>
<h3>Find a Park</h3>
<div id="map"></div>
<script>
function initMap() {
var Velocity = {lat: 38.308101, lng: -85.815464};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: Velocity
});
var marker = new google.maps.Marker({
position: Velocity,
map: map
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDSHCinT3IVWFCLUudbsMZV6644GNrGiwc&callback=initMap">
</script>
<script type="text/javascript">
//Create a gamesparks object to be used
var gamesparks = new GameSparks();
//Initialse the SDK
function init() {
gamesparks.initPreview({
key: document.getElementById('apiKey').value,
secret: document.getElementById('apiSecret').value,
credential: document.getElementById('apiCredential').value,
onNonce: onNonce,
onInit: onInit,
onMessage: onMessage,
logger: console.log,
});
}
function accountDetailsResponseCreator() {
var response = {
displayName: 'A User',
currencies: {Coins: 'A coin', Exp: 'A exp', LeadP: 'A lead p', HeroP: 'A hero p'}
}
accountDetailsResponse(response)
}
//Callback function to hmac sha256 a nonce with the secret. It's assumed you will have your own method of securing the secret;
function onNonce(nonce) {
return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(nonce, document.getElementById('apiSecret').value));
}
//Callback to handle when the SDK is initialised and ready to go
function onInit() {
console.log("Initialised");
}
//Callback to handle async messages from the gamesparks platform
function onMessage(message) {
console.log("onMessage");
}
//Response handler examples
function registerResponse(response) {
console.log(JSON.stringify(response));
}
function loginResponse(response) {
console.log(JSON.stringify(response));
}
function accountDetailsResponse(response) {
console.log (JSON.stringify(response));//logs the string to console
document.getElementById("displayName").innerHTML = (response.displayName);
document.getElementById("Coins").innerHTML = (response.currencies.Coins);
document.getElementById("Exp").innerHTML = (response.currencies.Exp);
document.getElementById("LeadP").innerHTML = (response.currencies.LeadP);
document.getElementById("HeroP").innerHTML = (response.currencies.HeroP); //returns value of name from string. I've tried doing each line with semicolons at the end, and all in a group with commas separating them. Both just give me the first variable and delete the rest.
}
function customEvent() {
gamesparks.sendWithData(
"LogEventRequest",
{
eventKey: "FIRST_EVENT",
NUMBER_ATTR: 123,
STRING_ATTR: "this is a string",
JSON_ATTR: {key1: 12, key2: "abc"}
},
function (response) {
console.log(JSON.stringify(response));
}
);
}
var apiKey = "2974660weiMa";
var apiSecret = "p5pFVnohi5eWPYETb4aPgeMLtd95bjfJ";
var myTimer = null;
var myRTSession = function () {
};
var numCycles = 0;
myRTSession.started = false;
myRTSession.onPlayerConnectCB = null;
myRTSession.onPlayerDisconnectCB = null;
myRTSession.onReadyCB = null;
myRTSession.onPacketCB = null;
myRTSession.session = null;
myRTSession.start = function (connectToken, host, port) {
var index = host.indexOf(":");
var theHost;
if (index > 0) {
theHost = host.slice(0, index);
} else {
theHost = host;
}
console.log(theHost + " : " + port);
myRTSession.session = GameSparksRT.getSession(connectToken, theHost, port, myRTSession);
if (myRTSession.session != null) {
myRTSession.started = true;
myRTSession.session.start();
} else {
myRTSession.started = false;
}
};
myRTSession.stop = function () {
myRTSession.started = false;
if (myRTSession.session != null) {
myRTSession.session.stop();
}
};
myRTSession.log = function (message) {
var peers = "|";
for (var k in myRTSession.session.activePeers) {
peers = peers + myRTSession.session.activePeers[k] + "|";
}
console.log(myRTSession.session.peerId + ": " + message + " peers:" + peers);
};
myRTSession.onPlayerConnect = function (peerId) {
myRTSession.log(" OnPlayerConnect:" + peerId);
if (myRTSession.onPlayerConnectCB != null) {
myRTSession.onPlayerConnectCB(peerId);
}
};
myRTSession.onPlayerDisconnect = function (peerId) {
myRTSession.log(" OnPlayerDisconnect:" + peerId);
if (myRTSession.onPlayerDisconnectCB != null) {
myRTSession.onPlayerDisconnectCB(peerId);
}
};
myRTSession.onReady = function (ready) {
myRTSession.log(" OnReady:" + ready.toString());
if (myRTSession.onReadyCB != null) {
myRTSession.onReadyCB(ready);
}
};
myRTSession.onPacket = function (packet) {
myRTSession.log(" OnPacket:" + packet.toString());
if (myRTSession.onPacketCB != null) {
myRTSession.onPacketCB(packet);
}
};
function testRT() {
myRTSession.stop();
gamesparks.initPreview({
key: apiKey,
secret: apiSecret,
credential: "",
onNonce: onNonceRT,
onInit: onInitRT,
onMessage: onMessageRT,
logger: console.log,
});
}
function onNonceRT(nonce) {
return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(nonce, apiSecret));
}
function onInitRT() {
console.log("Initialised");
gamesparks.deviceAuthenticationRequest((Math.floor(Math.random() * (999 - 1)) + 1).toString(), null, null, "js", null, null, function (response) {
if (response.error) {
console.error(JSON.stringify(response.error));
} else {
sendMatchmakingRequest();
}
});
}
//Callback to handle async messages from the gamesparks platform
function onMessageRT(message) {
//console.log("message " + JSON.stringify(message));
if (message["#class"] === ".MatchFoundMessage") {
var accessToken = message["accessToken"];
var host = message["host"];
var port = message["port"];
myRTSession.stop();
if (myTimer) {
clearTimeout(myTimer);
}
myTimer = setInterval(mainRTLoop, 10);
myRTSession.start(accessToken, host, port);
} else if (message["#class"] === ".MatchNotFoundMessage") {
console.log("MATCH NOT FOUND");
sendMatchmakingRequest();
}
}
function sendMatchmakingRequest() {
gamesparks.sendWithData("MatchmakingRequest",
{
skill: 1,
matchShortCode: "Match_STD"
},
function (response) {
if (response.error) {
console.error(JSON.stringify(response.error));
} else {
console.log("Match OK...");
}
}
);
}
function mainRTLoop() {
if (myRTSession.started) {
myRTSession.session.update();
var data = RTData.get();
data.setLong(1, numCycles);
myRTSession.session.sendRTData(1, GameSparksRT.deliveryIntent.RELIABLE, data, []);
numCycles++;
}
}
</script>
</body>
</html>
For the life of me, I have no idea what is happening or how to fix it. The problem pops up when I activate a button that references line 173
function loginResponse(response) {
console.log(JSON.stringify(response));
}
But don't let that affect your impartiality. I compared this code to earlier versions of the code I have and could not identify a change in any of my functions.
Well, bottom line is this: When you are an idiot, don't post questions to stackoverflow. No one will respond. Not because they are mean, but because learning the basics is important.
So the problem originated for me in the top of my code with this:
<button onClick='gamesparks.authenticationRequest(username, password, loginResponse)'>Login</button>
Weird, right? Not really. What had done was try to alter the input for the authentication request to match my html element inputs (see where my elements are labeled as username and password?) It didn't work, and I obviously just shelved that and moved on...and forgot. What I did was change "username" to "testuser". This matched the value I was trying to authenticate. Now, my baby is returning values on my testuser, and running like a dream.
Thanks for the tough love, stackoverflow.

500 (Internal Server Error) using jQuery $.post with CodeIgniter

It is a widely asked question to help with this error but I have spent all day reading other answers and creating various versions for my code and still can not get anything else then this error. So I ask for your help.
My view:
<html>
<head>
<title></title>
<?=$head?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=AIzaSyAhiKwDjhm1ZXS1jHBHErJf6pxT2TUCMM4"></script>
<script src="<?php echo base_url() ?>scripts/jquery.colorbox-min.js"></script>
<script src="<?php echo base_url() ?>scripts/gmaps.js"></script>
<link rel="stylesheet" href="<?php echo base_url() ?>css/colorbox.css">
<style type="text/css">
#map {
width: 700px;
height: 700px;
}
</style>
</head>
<body>
<button id="go-button" type="button">Click Me!</button>
<div class="multiselect">
<label><input type="checkbox" value="all" />All</label>
<label><input type="checkbox" name="filtrs1[]" value="manufacturer1" />manufacturer1</label>
<label><input type="checkbox" name="filtrs1[]" value="manufacturer2" />manufacturer2</label>
<label><input type="checkbox" name="filtrs1[]" value="manufacturer3" />manufacturer3</label>
<label><input type="checkbox" name="filtrs1[]" value="manufacturer4" />manufacturer4</label>
</div>
<div id="map"></div>
<script type="text/javascript">
var products= <?= json_encode($products);?>;
var allMap;
$(document).ready(function(){
var allMap = new GMaps({
el: '#map',
zoom: 7,
lat: 37.4419,
lng: -122.1419
});
loadJsonMap(allMap, products);
$('#go-button').click(function(){
var chb = $("input[name='filtrs1[]']:checked");
var filtrs1values = [];
$.each(chb,function(){
filtrs1values.push($(this).val());
});
$.post('<?php echo base_url() ?>index.php/products/filter', {
filtrs1 : filtrs1values
}, function(response){
allMap.removeMarkers();
loadJsonMap(allMap, response);
});
});
});
function loadJsonMap(map, data){
var markers_data = [];
$.each(data, function(key, val){
if (val.latitude != undefined && val.longitude != undefined) {
markers_data.push({
lat : val.latitude,
lng : val.longitude,
details : {
holder_id : val.holder_id
},
click : function(e){
if(e.details.holder_id !== undefined){
var url = '<?php echo base_url() ?>index.php/products/colorbox/' + e.details.holder_id;
$.colorbox({
open : true,
href : url,
iframe : false,
innerWidth : 400,
innerHeight : 400,
close : 'Aizvert'
});
}
}
});
}
});
map.addMarkers(markers_data);
}
</script>
</body>
</html>
where $.post calls for controller products:
public function filter()
{
$data['manufacturer'] = $this->input->post('filtrs1');
$result = $this->products_model->get_productsByManufacturer($data);
// $result = $this->security->get_csrf_token_name();
// $result = $this->security->get_csrf_hash();
header('Cache-Control: no-cache, must-revalidate');
header('Content-Type: application/json');
echo json_encode($result);
}
where in products_model:
function get_productsByManufacturer($data)
{
if(empty($data['manufacturer']){
$this->db->select("latitude,longitude, holder_id");
$query = $this->db->get('products');
return $query->result_array();
}else{
$this->db->select("latitude,longitude, holder_id");
$this->db->where_in('manufacturer', $data['manufacturer']);
$query = $this->db->get('products');
return $query->result_array();
}
}
I get error on $.post line. I checked filtrs1values array using consule.log and got ["manufacturer3", "manufacturer4"]. Also I have changed my controller and model code multiple times but always get the same error.

Google conversions not registering within PHP page

Although relatively new to coding, I have successfully implemented a number of tracking codes before, but I am having serious problems getting one conversion code to register on my site.
Whilst I have put it into the relevant section of PHP in the code, and even done test conversions and seen it in the source, Google has failed to register a single conversion and the goal still shows up as 'Unverified'.
I have read various blogs and what Google has to say about implementing the code in PHP - most of which seem to disagree with one another. If anyone has any ideas, I would be hugely grateful as it is a key indicator to tracking my AdWords performance.
Below is the code that Google gives me to implement untouched:
<!-- Google Code for Almost there Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 974608389;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "d5KfCMunhgUQhbDd0AM";
var google_conversion_value = 0;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/974608389/?value=0&label=d5KfCMunhgUQhbDd0AM&guid=ON&script=0"/>
</div>
</noscript>
Now the code the way Google wants you to edit it for PHP, detailed under the section here: https://support.google.com/adwords/answer/1722054?hl=en-GB
<!-- Google Code for Almost there Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 974608389;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "d5KfCMunhgUQhbDd0AM";
if (<%= totalValue %) {
var google_conversion_value = <%= totalValue %>;
}
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/974608389/?value=0&label=d5KfCMunhgUQhbDd0AM&guid=ON&script=0"/>
</div>
</noscript>
I have wasted about 3 days on this on and off now and have spent long enough trying to click on adverts and creating fake accounts to test it with to get it to trigger.
As another safeguard I will post the relevant PHP section in it's entirety below too.
It's a part triggered to confirm a subscription payment may be useful to see you can never have too much information, diagnosing a problem.
<?php
/* Template Name: Subscription Confirmation */
if (isset($_POST['activate_subscription']) && isset($_POST['token'])) {
$activation = completeSubscription($_POST['token']);
//completeSubscription Handles everything here. If this even runs, it's all gone wrong.
$activate_failed = true;
} else if (isset($_GET['token']) && isset($_GET['PayerID'])) {
$transaction = getTransactionDetails($_GET['token']);
if ($transaction['ACK'] == "Success") $sub = updateSubscriptionDetails($transaction);
} else {
header("Location: /join/membership/");
exit();
}
get_header();
?>
<div class="row subhero">
<div class="twelve columns">
<?php if (!isset($activate_failed) && $transaction['ACK'] == "Success") { ?>
<h1>Almost there!</h1>
<p class="subheader">Thank you for configuring your subscription with PayPal.</p>
//***************** ANALYTICS CODE
<!-- Google Code for Subscription Conf Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 974608389;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "d5KfCMunhgUQhbDd0AM";
if (<%= totalValue %) {
var google_conversion_value = <%= totalValue %>;
}
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/974608389/?value=0&label=d5KfCMunhgUQhbDd0AM&guid=ON&script=0"/>
</div>
</noscript>
//*********************END OF ANALYTICS CODE
</div>
</div>
</div> <!-- end container -->
<div class="buyticketarea">
<div class="row">
<div class="eight columns offset-by-two">
<p class="subheader">Please confirm the following details. Once you proceed you will be billed immediately for your first month of <strong><?php echo $transaction['L_NAME0']; ?></strong> at <strong>£<?php echo $transaction['L_AMT0']; ?>.</strong></p>
<p class="subheader">Additionally, you will be billed <strong>£<?php echo $transaction['L_AMT0']; ?></strong> on the <strong><?php echo date('j'); ?><sup><?php echo date('S'); ?></sup></strong> of each month, starting on <strong><?php echo getNextBillingDayHuman(); ?>.</strong></p>
<p class="subheader">If you're happy to proceed...</p>
<form method="post">
<input type="hidden" name="sub_id" value="<?php echo $transaction['INVNUM']; ?>" />
<input type="hidden" name="token" value="<?php echo $_GET['token']; ?>" />
<input type="hidden" name="PayerID" value="<?php echo $_GET['PayerID']; ?>" />
<input class="button" type="submit" name="activate_subscription" value="Activate Subscription" />
</form>
</div>
</div>
</div>
This line looks wrong to me:
if (<%= totalValue %) {
var google_conversion_value = <%= totalValue %>;
}
Looking at other examples it should be:
if (<?php echo $totalValue ?>) {
var google_conversion_value = <?php echo totalValue ?>;
}
But, you aren't setting the value for $totalValue so maybe all conversions have equal value? In which case you should just use:
var google_conversion_value = 10;

Vimeo embed (froogaloop) SQL "while loop" issue

Link:
this is the page I am working on
So, I am trying to create a page that will produce a playlist of vimeo videos that will play one after another. Eventually I will have them hide and show using jquery or something so that only one embedded video iframe will appear at a time. In the meantime I am simply trying to get the vimeo api to give me control over each individual object.
So the desired result for now would be have each set up buttons control each video with its same $nummy value
where $nummy is the order in the list
The issue is that at the moment ONLY THE LAST video in the list responds to its own button-set's commands.
Here's the code WITH PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test The Loop2</title>
<script type="text/javascript" src="http://a.vimeocdn.com/js/froogaloop2.min.js"></script>
</head>
<body>
<?
//db connect
$con = mysql_connect("d######t","db######104","no#######s");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//db select
mysql_select_db("db337100104", $con);
$result = mysql_query("SELECT * FROM vim_playlist1");
while($row = mysql_fetch_array($result))
{
$nummy = $row['listnum'] ;
$url = $row['url'] ;
$nexty = $nummy+1 ;
//not an area of php
?>
<iframe class="vimeo" id="play<? echo $nummy ?>" src="http://player.vimeo.com/video/<? echo $row['url'] ?>?api=1&player_id=play<? echo $nummy?>" width="500" height="281" frameborder="0"></iframe>
<br />
<button id="playButton<? echo $nummy ?>">Play</button>
<button id="pauseButton<? echo $nummy ?>">Pause</button>
<button id="unloadButton<? echo $nummy ?>">Unload</button>
<script>
function ready(player_id)
{
$f('play<? echo $nummy?>').addEvent('ready', function()
{
$f('play<? echo $nummy?>').addEvent('finish', onFinish);
});
function onFinish(play<? echo $nummy?>)
{
$f('play<? echo $nexty ?>').api('play');
}
document.getElementById('playButton<? echo $nummy ?>').addEventListener('click', function() {
$f('play<? echo $nummy?>').api('play');
});
document.getElementById('pauseButton<? echo $nummy ?>').addEventListener('click', function() {
$f('play<? echo $nummy?>').api('pause');
});
document.getElementById('unloadButton<? echo $nummy ?>').addEventListener('click', function() {
$f('play<? echo $nummy?>').api('unload');
});
}
window.addEventListener('load', function() {
//Attach the ready event to the iframe
$f(document.getElementById('play<? echo $nummy?>')).addEvent('ready', ready);
});
</script>
<hr />
<?
//end of loop
}
?>
</body>
</html>
You are overwriting your ready function in every iteration of your loop. So only the last ready function will be executed.
An example solution would be to replace ready with ready<?php echo $nummy ?> (I suppose that $nummy is unique):
function ready<?php echo $nummy ?>(player_id) {
// your function body
}
window.addEventListener('load', function() {
//Attach the ready event to the iframe
$f(document.getElementById('play<? echo $nummy?>')).addEvent('ready', ready<?php echo $nummy ?>);
});
P.s.: It is not an ideal solution. But a possible solution.

Pass Variable From HTML Page To PHP Script

I wonder whether someone may be able to help me please.
The code below allows users to delete images from a gallery.
Full Script Minus Styling
<?php session_start();
$_SESSION['userid']=$_POST['userid'];
$_SESSION['locationid']=$_POST['locationid'];
//echo $_SESSION['userid'];
//echo $_SESSION['locationid'];
?>
<?php
$galleryPath = 'UploadedFiles/' . $_SESSION['userid'] . '/' . $_SESSION['locationid'] . '/';
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$descriptions = new DOMDocument('1.0');
$descriptions->load($absGalleryPath . 'files.xml');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=0.3">
<title>Galleria Twelve Theme</title>
<style>
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/jquery-ui-1.8.19.custom.min.js"></script>
<script src="galleria/galleria-1.2.7.min.js"></script>
<script src="galleria/themes/twelve/galleria.twelve.min.js"></script>
<script src="galleria/plugins/history/galleria.history.min.js"></script>
<link rel="stylesheet" href="galleria/themes/twelve/galleria.twelve.css">
<style>
.galleria-thumbnails .btn-delete {
display: block; /* Or just use a div instead of a span*/
position: absolute; bottom : 0px; /*align at the bottom*/
width: 80px;
height: 17px;
cursor: pointer;
background: url(trash8.gif) no-repeat bottom; }
</style>
<script type="text/javascript">
Galleria.ready(function() {
this.$('thumblink').click();
$(".galleria-image").append(
"<span class='btn-delete ui-icon ui-icon-trash'></span>");
$(".btn-delete").live("click", function(){
// you do not need to find img and then src... just use id of image
var img = $(this).closest(".galleria-image").find("img");
var userid=$(".hiddenvals").attr('userid');
var locationid=$(".hiddenvals").attr('locationid');
// send the AJAX request
$.ajax({
url : 'delete3.php?userid='+userid+'&locationid='+locationid,
type : 'post',
data : { image : img.attr('src') },
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
return false;
});
});
</script>
</head>
<body>
<ul id="navigation">
<li class="left">
<div align="center">← Add Images</div>
</li>
</ul>
<form id="viewimages" name="viewimages" class="page" action="index.php" method="post"> <input name="userid" class="hiddenvals" type="hidden" value="<?php echo $_SESSION['userid']; ?>"> <input name="locationid" class="hiddenvals" type="hidden" value="<?php echo $_SESSION['locationid']; ?>"></form>
<div class="content">
<h1>Galleria Twelve Theme</h1>
<p>Demonstrating a simple example.</p>
<!-- Adding gallery images. We use resized thumbnails here for better performance, but it’s not necessary -->
<div id="galleria">
<?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :
$xmlFile = $descriptions->documentElement->childNodes->item($i);
$name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');
$description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');
$source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));
?>
<img data-title="<b>Image Name: </b> <?php echo $name; ?>" data-description="<b>Description:</b> <?php echo $description; ?>" src="<?php echo $source; ?>">
<?php endfor; ?>
</body>
</html>
In essence, the user clicks on a delete icon, then the 'delete.php' script called in the code above deletes the image from the server. This all works well.
What I'm struggling with is how to pass two variable values to the 'delete.php' script. These are 'userid' and 'locationid'.
I've tried adding the following to the beginning of my 'delete.php':
<?php session_start();
$_SESSION['userid']=$_POST['userid'];
$_SESSION['locationid']=$_POST['locationid'];
But the values are not carried over. I suspect that this may be down to the fact the the forms 'POST' action is being used to navigate to another HTML page, although I'm no expert, so I may have got this wrong.
I've done quite a bit of reading and searched for tutorials on how to go about getting around this problem, but I've not found anything that seems to suggest a solution.
I just wondered whether someone may be able to look at this please, and offers some guidance on how I can pass these two values to my 'delete.php' script.
Many thanks and kind regards
If they are in the html page add them to the ajax request:
{ image : img.attr('src'), userid: "VALUE", locationid: "VALUE"},
Try to send ids from your html page like
$.ajax({
url : 'delete.php?userid=2&locationid=4',
........
Then in php
$uid=$_POST['userid'];
$locid=$_POST['locationid'];
If you want to get userid and locationid dynamically for each image.
FIRST; in you btn-delete class add uid and locid attribute. I suppose you are looping through PHP.
LIKE ===>
<input type="button" class="btn-delete" uid="2" locid="5">
Then in your script
<script type="text/javascript">
Galleria.ready(function() {
this.$('thumblink').click();
$(".galleria-image").append(
"<span class='btn-delete ui-icon ui-icon-trash'></span>");
$(".btn-delete").live("click", function(){
// you do not need to find img and then src... just use id of image
var img = $(this).closest(".galleria-image").find("img");
var uid=$(this).attr('uid');
var locid=$(this).attr('locid');
// send the AJAX request
$.ajax({
url : 'delete.php?userid='+uid+'&locationid='+locid,
type : 'post',
data : { image : img.attr('src') },
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
return false;
});
});
</script>
var id=$(this).attr('id');
var userid=$('#userid').val();
var locationid=$('#locationid').val();
$.ajax({
url : 'delete.php',
type : 'post',
dataType : 'json',
data : { image : img.attr('src'), userid: userid, locationid: locationid},
,
success : function(){
alert('Deleting image... ');
img.parent().fadeOut('slow');
}
});
add dataType : 'json' and get posted value in delete.php by
$userid=$_POST['userid'];
$locationid=$_POST['locationid'];

Categories