I am trying to create a facebook signup. I am receiving the signed_request from facebook that is being decoded and displayed as the following:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 0
[issued_at] => **********
[oauth_token] => *******************************************************************************************************************
[registration] => Array
(
[name] => Darren West
[email] => dwest#madeup.com
[password] => IJ8sU10lw
)
[registration_metadata] => Array
(
[fields] => name,email,password
)
[user] => Array
(
[country] => us
[locale] => en_US
)
[user_id] => ***************
)
I want to add the three fields within the registration array to a hidden form and automatically submit it to another page for saving to the database.
My question is how do I extract the name, email, and password from the registration array and assign them to individual variables. I used the following, but I don't get a result:
print $response['registration']->password;
Any help would be greatly appreciated.
Many thanks,
neojakey
print $response['registration']['password'];
Related
Here i am having one multidimensional array , using this array i want to take from emails array i want to take user email value like abc#gmail.com and from name array i want to take value givenName like Raju and from image array i want to take url like www.domain.com
print_r($user_info);
Array
(
[kind] => plus#person
[etag] => "EhMivDE25UysA1M2v-A/ZXQsxHAN9QSz-hQoXfQGzFyLWdQ"
[gender] => male
[emails] => Array
(
[0] => Array
(
[value] => abc#gmail.com
[type] => account
)
)
[objectType] => person
[id] => 100776010499118027035
[displayName] => Raju r
[name] => Array
(
[familyName] => r
[givenName] => Raju
)
[url] => https://plus.google.com/100776010499118027035
[image] => Array
(
[url] => www.domain.com
[isDefault] =>
)
[isPlusUser] => 1
[language] => en
[circledByCount] => 1
[verified] =>
[domain] => www.facebook.com
)
Expected Results
abc#gmail.com
Raju
www.domain.com
I tried like this
foreach($user_info['emails'] as $result){
$user_email = $result['value'];
foreach($result['name'] as $nameresult){
$user_name = $nameresult['givenName'];
}
}
Seems name does not seems to be an array of arrays like emails. So you can directly take that name instead of inner loop
foreach($user_info['emails'] as $result){
$user_email = $result['value'];
}
In this it the email value will be overridden each time and will hold only last email element value.
&
$user_info['name']['familyName'];
$user_info['image']['url'];
What I understand from the above set of data is that a user will have multiple email ids and a one and one image url. So above logic works.
I am attempting to get around having to raise the max_input_vars parameter when submitting a large form. My thought was to jsonify the form, create a second form with a single field in it, put the jsonified string into that single field, submit, decode as an array, and then replace the POST array with the decoded data. I am plugging this into an existing system so for this to work I would need the new array to have the same structure as the raw post would. However, I am running into an issue where regardless of how I encode the data I am losing info and structure beyond the first depth of the array. I have tried both using this library to encode the form:
https://github.com/macek/jquery-serialize-object
As well as jQuery(form).serializeArray(), each of which delivers results that decode in their own unintended ways. This is what the raw post data looks like when I don't intercept the form and dump it with print_r($_POST):
Array
(
[closedpostboxesnonce] => 9d9dc8fa74
[meta-box-order-nonce] => 520ef5d263
[update-nav-menu-nonce] => cfea78920d
[_wp_http_referer] => /wp-admin/nav-menus.php
[action] => update
[menu] => 2
[menu-name] => Left Sidebar Menu
[save_menu] => Save Menu
[qtranslate-fields] => Array
(
[menu-item-title] => Array
(
[3871] => Array
(
[en] => Knowledge Center
[ja] => Knowledge Center
[ko] => Knowledge Center
[zh] => Knowledge Center
[qtranslate-separator] => [
)
The data when I use the jquery-serialize-object library above to encode the form data, then decode it with json_decode($_POST["allinputs"],true):
Array
(
[closedpostboxesnonce] => 9d9dc8fa74
[meta-box-order-nonce] => 520ef5d263
[update-nav-menu-nonce] => cfea78920d
[_wp_http_referer] => /wp-admin/nav-menus.php
[action] => update
[menu] => 2
[menu-name] => Left Sidebar Menu
[qtranslate-fields[menu-item-title][3871][en]] => Knowledge Center
[qtranslate-fields[menu-item-title][3871][ja]] => Knowledge Center
[qtranslate-fields[menu-item-title][3871][ko]] => Knowledge Center
[qtranslate-fields[menu-item-title][3871][zh]] => Knowledge Center
Using jQuery(form).serializeArray() to encode, and $allinputs = (array)(json_decode($_POST["allinputs"])); to decode:
Array
(
[0] => stdClass Object
(
[name] => closedpostboxesnonce
[value] => 9d9dc8fa74
)
[1] => stdClass Object
(
[name] => meta-box-order-nonce
[value] => 520ef5d263
)
[2] => stdClass Object
(
[name] => update-nav-menu-nonce
[value] => cfea78920d
)
Is there a way to get the data encoded and then decoded while retaining the original structure?
Edit: using #think-win-win 's suggestion of passing true as the second parameter of json_decode yields:
Array
(
[0] => Array
(
[name] => closedpostboxesnonce
[value] => 9d9dc8fa74
)
[1] => Array
(
[name] => meta-box-order-nonce
[value] => 520ef5d263
)
[2] => Array
(
[name] => update-nav-menu-nonce
[value] => cfea78920d
)
It is one of the ones that I tried, along with a couple of others, but I felt the post was getting too long to include them all. The above one loses the associativeness of the top level of the array, in addition to converting the deeper levels to:
[7] => Array
(
[name] => qtranslate-fields[menu-item-title][3871][en]
[value] => Knowledge Center
)
[8] => Array
(
[name] => qtranslate-fields[menu-item-title][3871][ja]
[value] => Knowledge Center
)
I am using mailchimp's webhook feature to (eventually) run a script on my app that will mark a user as unsubscribed from the newsletter if they unsubscribe through mailchimp.
Mailchimp is passing the following array to my script using POST.
Array
(
[type] => unsubscribe
[fired_at] => 2014-01-12 12:56:23
[data] => Array
(
[action] => unsub
[reason] => manual
[id] => 1b3a2f11af
[email] => email#domain.com
[email_type] => html
[ip_opt] => xxx.xxx.xxx.xxx
[web_id] => 128403001
[merges] => Array
(
[EMAIL] => email#domain.com
[FNAME] => FNAME
[LNAME] => LNAME
)
[list_id] => 5c30250cdb
)
)
My issue is, how can I get the [email] value out of it so that I can then pass that as a variable to update the database?
$email = $_POST ['data']['email'];
Try this code:
$result_array = $_POST;
echo $result_array["data"]["email"]; // or $_POST["data"]["email"];
I have made a simple facebook register widget.
On register the App sends the data to send.php
On send.php I have
print_r($response);
And I get something like this:
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1367953200
[issued_at] => 1367946138
[oauth_token] => BAAE0refKufgBAORkK7hUaVpF8MnFygoqHAHrO3nRJMyNjvJx6RjiMjoqbz2YlfqeogcIPGJJaIgD0xtxhBj1WRgQ5F5SidjwM7ZCKOyZBlEuatIqIccbjGj2uMV5hqtKtZA1g7hOEqMeZAEwmnO6SgRgsb9ittKZCDnPfoxYxCxZAZBAhIKX457IG5ZB4yknv9FZB8QUG7Pt0mfBRQUYG12KoTmO7QRH20LP65FyPqTi7mAZDZD
[registration] => Array
(
[name] => derp derp
[email] => ddddd#gmail.com
[location] => Array
(
[name] => Vienna, Austria
[id] => 1.1116511224109E+14
)
[gender] => male
[phone] => sss
)
[registration_metadata] => Array
(
[fields] => [ {'name':'name'}, {'name':'email'}, {'name':'location'}, {'name':'gender'}, {'name':'phone', 'description':'Phone Number', 'type':'text'},]
)
[user] => Array
(
[country] => at
[locale] => en_US
)
[user_id] => 100000506481284
)
So the data gets passed without a problem but how can I access a specific value?
For example text book array stuff doesnt appear to be working like:
print $response[0];
Gives me an error:
Notice: Undefined offset: 0 in C:\xampp\htdocs\ddd\send.php on line 38
How else can I access the data?
For example how could I store country, email, name or whatever in their own variables so I can echo them later? Its there but I cant seem to figure out how to "digest" it properly with php.
There is no index 0 in the array you pasted..
Use it like
$email = $response['registration']['email'];
If it was an object instead of an array you would do
$email = $response->registration->email
This is very basic PHP array handling.
http://php.net/manual/en/language.types.array.php
I have a facebook application and a tab page which links http://localhost/a/index.php, I have successfully add this tab page to my pages. I wrote in index.php
$checkLoggedIn = $facebook->getSignedRequest();
it return me like this
Array
(
[algorithm] => HMAC-SHA256
[expires] => 1324648800
[issued_at] => 1324644411
[oauth_token] => AAACMkfuFjmIBAEJ9zqtJVvDK08aXlO1wSEFVNvekyCWcZBtnQcJ8BTCYfwZBMyrom5nazjPCsF56v4hLCBi2VywUzgrLSTYr9sbMmTWDN5QFFeOBfU
[page] => Array
(
[id] => 309081639123289
[liked] => 1
[admin] => 1
)
[user] => Array
(
[country] => bd
[locale] => en_US
[age] => Array
(
[min] => 21
)
)
[user_id] => 1549070809
)
its ok for me. I have also another link on that page is start.php with same code but it return to me like this
Array
(
[algorithm] => HMAC-SHA256
[code] => 2.AQAHgyMnInvOgkoU.3600.1324648800.5-1549070809|OMFOQPTFesejPmg0h2SfwwNGGEY
[issued_at] => 1324644436
[user_id] => 1549070809
)
what can I now? to get same object. because they are in same iframe.
This is because the facebook sdk only saves some information in the session (your second array). To remember the page, you have to manually save it.