{"id":71,"date":"2012-08-22T19:03:00","date_gmt":"2012-08-22T19:03:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2012\/08\/22\/facebook-registration-plugin-with-custom-fields-and-examples\/"},"modified":"2021-02-22T01:00:15","modified_gmt":"2021-02-22T01:00:15","slug":"acebook-registration-plugin-with-custom-fields-and-examples","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2012\/08\/acebook-registration-plugin-with-custom-fields-and-examples.html","title":{"rendered":"Facebook Registration Plugin (With Custom Fields and Examples)"},"content":{"rendered":"<p>Facebook Registration Plugin (With Custom Fields and Examples)<\/p>\n<p>In this post, I will show you how to implement facebook registration plugin, and I will create some examples, with custom fields, with both the iframe version and XFBML.<\/p>\n<p>You can check the examples directly in here: <a href=\"http:\/\/lab.tech-and-dev.com\/facebookRegistration.php\" target=\"_blank\" rel=\"noopener\">Facebook Registration Plugin Examples<\/a><\/p>\n<p>Scroll down for the entire source code.<\/p>\n<p>The facebook social plugin can be used for users with a facebook account, or users without a facebook account.<br \/>\nIf the user does not have a facebook account, or if the user is not logged in to their facebook account, the below subscription form will be displayed.<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/form.png\"><img decoding=\"async\" title=\"Facebook Registration Plugin\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/form.png\" alt=\"Facebook Registration Plugin\" border=\"0\" \/><\/a><\/div>\n<p>If the user has a facebook account and is logged in, the registration form will be pre-filled to save the user time. This is very useful to register the user quickly with one mouse click.<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/pre-filled.png\"><img decoding=\"async\" title=\"Facebook Registration Plugin Pre-filled\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/pre-filled.png\" alt=\"Facebook Registration Plugin Pre-filled\" border=\"0\" \/><\/a><\/div>\n<p>Sometimes you might only want users with a facebook account to be able to register on your site. This can be specified with a parameter that will be explained later on. The following registration form will be displayed if the user is not logged in to facebook.<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/facebook-registration-onlyfb.png\"><img decoding=\"async\" title=\"Facebook Registration Plugin Force Login\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/facebook-registration-onlyfb.png\" alt=\"Facebook Registration Plugin Force Login\" border=\"0\" \/><\/a><\/div>\n<p>I will not go in the already explained details on facebook. In this post, I will assume that you have already read this: <a href=\"http:\/\/developers.facebook.com\/docs\/plugins\/registration\/\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/developers.facebook.com\/docs\/plugins\/registration\/<\/a><\/p>\n<p>For this plugin to work, you will need a facebook app id and a facebook app secret, if you havne&#8217;t created a facebook app yet, I suggest you read this tutorial first to create an app: <a href=\"http:\/\/www.tech-and-dev.com\/2012\/08\/facebook-app-tutorial-basics.html\" target=\"_blank\" rel=\"noopener\">Facebook App Tutorial &#8211; The Basics<\/a><\/p>\n<p>You will also need to set the redirect URI, in my case, I&#8217;m going to set it to the same file location of the subscription form in order to display the output.<\/p>\n<h3><\/h3>\n<h3><\/h3>\n<h3 style=\"color: #3d85c6;\">Facebook registration plugin (iframe) without custom fields:<\/h3>\n<p>In the first example, I&#8217;m going to build the registration plugin using iframe and <b>without any custom fields<\/b>. Simply the code will be as follows:<\/p>\n<div style=\"background-color: #f3f3f3; color: #38761d; font-family: 'Courier New',Courier,monospace; padding: 5px;\">\n<div><span style=\"font-size: small;\">&lt;?php<\/span><\/div>\n<div><span style=\"font-size: small;\">$API_KEY = &#8216;463292747036958&#8217;;<\/span><\/div>\n<div><span style=\"font-size: small;\">$API_SECRET = &#8216;GET_YOUR_APP_SECRET&#8217;;<\/span><\/div>\n<div><span style=\"font-size: small;\">$redirect_URI = &#8216;http:\/\/lab.tech-and-dev.com\/facebookRegistration.php&#8217;;<\/span><\/div>\n<div><span style=\"font-size: small;\">?&gt;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div><span style=\"font-size: small;\">&lt;script src=&#8221;https:\/\/connect.facebook.net\/en_US\/all.js#appId=&lt;?php echo $API_KEY; ?&gt;&amp;xfbml=1&#8243;&gt;&lt;\/script&gt;<\/span><\/div>\n<div><span style=\"font-size: small;\">&lt;div id=&#8221;fb-root&#8221;&gt;&lt;\/div&gt;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div><span style=\"font-size: small;\">&lt;h2&gt;Without Custom Fields&lt;\/h2&gt;<\/span><\/div>\n<div><span style=\"font-size: small;\">&lt;iframe src=&#8221;http:\/\/www.facebook.com\/plugins\/registration?<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0client_id=&lt;?php echo $API_KEY; ?&gt;&amp;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0redirect_uri=&lt;?php echo $redirect_URI; ?&gt;&amp;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0fb_only=false&amp;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \u00a0fields=name,birthday,gender,location,email&#8221;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 scrolling=&#8221;auto&#8221;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 frameborder=&#8221;no&#8221;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 style=&#8221;border:none&#8221;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 allowTransparency=&#8221;true&#8221;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 width=&#8221;530&#8243;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0\u00a0\u00a0 height=&#8221;330&#8243;<\/span><\/div>\n<div><span style=\"font-size: small;\">&gt;<\/span><\/div>\n<div><span style=\"font-size: small;\">&lt;\/iframe&gt;<\/span><\/div>\n<div><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<p><span style=\"font-size: small;\">&lt;?php<br \/>\nif ($_REQUEST[&#8216;signed_request&#8217;])<br \/>\n{<br \/>\n$response = parse_signed_request($_REQUEST[&#8216;signed_request&#8217;], $API_SECRET);\/\/secret<\/span><\/p>\n<p>if($response)<br \/>\n{<br \/>\n\/\/Fields values<br \/>\n$email=$response[&#8216;registration&#8217;][&#8217;email&#8217;];<br \/>\n$name=$response[&#8216;registration&#8217;][&#8216;name&#8217;];<br \/>\n$gender=$response[&#8216;registration&#8217;][&#8216;gender&#8217;];<br \/>\n$user_fb_id=$response[&#8216;user_id&#8217;];<br \/>\n$location=$response[&#8216;registration&#8217;][&#8216;location&#8217;][&#8216;name&#8217;];<br \/>\n$bday = $response[&#8216;registration&#8217;][&#8216;birthday&#8217;];<\/p>\n<p>\/\/print entire array response<br \/>\necho &#8216;&lt;h3&gt;Response Array&lt;\/h3&gt;&#8217;;<br \/>\necho &#8216;&lt;pre&gt;&#8217;;<br \/>\nprint_r($response);<br \/>\necho &#8216;&lt;\/pre&gt;&#8217;;<\/p>\n<p>\/\/print values<br \/>\necho &#8216;&lt;h3&gt;Fields Values&lt;\/h3&gt;&#8217;;<br \/>\necho &#8217;email: &#8216; . $email . &#8216;&lt;br \/&gt;&#8217;;<br \/>\necho &#8216;Name: &#8216; . $name . &#8216;&lt;br \/&gt;&#8217;;<br \/>\necho &#8216;Gender: &#8216; . $gender . &#8216;&lt;br \/&gt;&#8217;;<br \/>\necho &#8216;Facebook Id: &#8216; . $user_fb_id . &#8216;&lt;br \/&gt;&#8217;;<br \/>\necho &#8216;Location: &#8216; . $location . &#8216;&lt;br \/&gt;&#8217;;<br \/>\necho &#8216;Birthday: &#8216; . $bday . &#8216;&lt;br \/&gt;&#8217;;<\/p>\n<p>}<br \/>\n}<br \/>\n?&gt;<\/p>\n<div><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<p><span style=\"font-size: small;\">&lt;?php<br \/>\nfunction parse_signed_request($signed_request, $secret)<br \/>\n{<br \/>\nlist($encoded_sig, $payload) = explode(&#8216;.&#8217;, $signed_request, 2); <\/span><\/p>\n<p>\/\/ decode the data<br \/>\n$sig = base64_url_decode($encoded_sig);<br \/>\n$data = json_decode(base64_url_decode($payload), true);<\/p>\n<p>if (strtoupper($data[&#8216;algorithm&#8217;]) !== &#8216;HMAC-SHA256&#8217;)<br \/>\n{<br \/>\nerror_log(&#8216;Unknown algorithm. Expected HMAC-SHA256&#8217;);<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>\/\/ check sig<br \/>\n$expected_sig = hash_hmac(&#8216;sha256&#8217;, $payload, $secret, $raw = true);<br \/>\nif ($sig !== $expected_sig)<br \/>\n{<br \/>\nerror_log(&#8216;Bad Signed JSON signature!&#8217;);<br \/>\nreturn null;<br \/>\n}<\/p>\n<p>return $data;<br \/>\n}<\/p>\n<p>function base64_url_decode($input)<br \/>\n{<br \/>\nreturn base64_decode(strtr($input, &#8216;-_&#8217;, &#8216;+\/&#8217;));<br \/>\n}<br \/>\n?&gt;<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<h3 style=\"color: #3d85c6; text-align: justify;\">Facebook registration plugin (iframe) with custom fields:<\/h3>\n<div style=\"text-align: justify;\">In this example, I&#8217;m going to build the registration plugin using iframe and <b>with custom fields<\/b>.<\/div>\n<div style=\"text-align: justify;\">To use custom fields, we will need to use JSON arrays<\/div>\n<div style=\"text-align: justify;\">The below example is an array from facebook tutorial, you can define checkbox, date, select, captcha to be filled&#8230;<\/div>\n<p>&nbsp;<\/p>\n<div style=\"background-color: #f3f3f3; color: #38761d; padding: 5px;\">\n<pre><code>[\r\n {'name':'name'},\r\n {'name':'email'},\r\n {'name':'location'},\r\n {'name':'gender'},\r\n {'name':'birthday'},\r\n {'name':'password'},\r\n {'name':'like',       'description':'Do you like this plugin?', 'type':'checkbox',  'default':'checked'},\r\n {'name':'phone',      'description':'Phone Number',             'type':'text'},\r\n {'name':'anniversary','description':'Anniversary',              'type':'date'},\r\n {'name':'captain',    'description':'Best Captain',             'type':'select',    'options':{'P':'Jean-Luc Picard','K':'James T. Kirk'}},\r\n {'name':'force',      'description':'Which side?',              'type':'select',    'options':{'jedi':'Jedi','sith':'Sith'}, 'default':'sith'},\r\n {'name':'live',       'description':'Best Place to Live',       'type':'typeahead', 'categories':['city','country','state_province']},\r\n {'name':'captcha'}\r\n]<\/code><\/pre>\n<\/div>\n<p>The code will be as follows:<\/p>\n<div style=\"background-color: #f3f3f3; color: #38761d; font-family: 'Courier New',Courier,monospace; padding: 5px;\"><span style=\"font-size: small;\">&lt;?php<\/span><br \/>\n<span style=\"font-size: small;\">$API_KEY = &#8216;463292747036958&#8217;;<\/span><br \/>\n<span style=\"font-size: small;\">$API_SECRET = &#8216;GET_YOUR_APP_SECRET&#8217;;<\/span><br \/>\n<span style=\"font-size: small;\">$redirect_URI = &#8216;http:\/\/lab.tech-and-dev.com\/facebookRegistration.php&#8217;;<\/span><br \/>\n<span style=\"font-size: small;\">?&gt;<\/span><br \/>\n<span style=\"font-size: small;\"><br \/>\n<\/span><span style=\"font-size: small;\">&lt;script src=&#8221;https:\/\/connect.facebook.net\/en_US\/all.js#appId=&lt;?php echo $API_KEY; ?&gt;&amp;xfbml=1&#8243;&gt;&lt;\/script&gt;<\/span><br \/>\n<span style=\"font-size: small;\">&lt;div id=&#8221;fb-root&#8221;&gt;&lt;\/div&gt;<\/span><br \/>\n<span style=\"font-size: small;\"><br \/>\n<\/span><span style=\"font-size: small;\">&lt;h2&gt;With Custom Fields&lt;\/h2&gt;<br \/>\n&lt;iframe src=&#8221;http:\/\/www.facebook.com\/plugins\/registration?<br \/>\nclient_id=&lt;?php echo $API_KEY; ?&gt;&amp;<br \/>\nredirect_uri=&lt;?php echo $redirect_URI; ?&gt;&amp;<br \/>\nfb_only=false&amp;<br \/>\nfields=[<br \/>\n{&#8216;name&#8217;:&#8217;name&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;birthday&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;gender&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;location&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;email&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;favoriteFood&#8217;, &#8216;description&#8217;:&#8217;Favorite Food&#8217;, &#8216;type&#8217;:&#8217;select&#8217;, &#8216;options&#8217;:{&#8216;0&#8242;:&#8217;Pizza&#8217;,&#8217;1&#8242;:&#8217;Burger&#8217;,&#8217;2&#8242;:&#8217;Hot Dog&#8217;,&#8217;3&#8242;:&#8217;Tuna&#8217;}},<br \/>\n{&#8216;name&#8217;:&#8217;graduated&#8217;, &#8216;description&#8217;:&#8217;Graduation Date&#8217;, &#8216;type&#8217;:&#8217;date&#8217;},<br \/>\n]&#8221;<br \/>\nscrolling=&#8221;auto&#8221;<br \/>\nframeborder=&#8221;no&#8221;<br \/>\nstyle=&#8221;border:none&#8221;<br \/>\nallowTransparency=&#8221;true&#8221;<br \/>\nwidth=&#8221;530&#8243;<br \/>\nheight=&#8221;400&#8243;<br \/>\n&gt;<br \/>\n&lt;\/iframe&gt;<\/span><\/div>\n<div style=\"background-color: #f3f3f3; color: #38761d; font-family: 'Courier New',Courier,monospace; padding: 5px;\"><\/div>\n<div style=\"background-color: #f3f3f3; color: #38761d; padding: 5px;\"><span style=\"font-size: small;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">&lt;?php <\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">if ($_REQUEST[&#8216;signed_request&#8217;])<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $response = parse_signed_request($_REQUEST[&#8216;signed_request&#8217;], $API_SECRET);\/\/secret<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if($response)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/Fields values<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $email=$response[&#8216;registration&#8217;][&#8217;email&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $name=$response[&#8216;registration&#8217;][&#8216;name&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $gender=$response[&#8216;registration&#8217;][&#8216;gender&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $user_fb_id=$response[&#8216;user_id&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $location=$response[&#8216;registration&#8217;][&#8216;location&#8217;][&#8216;name&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $bday = $response[&#8216;registration&#8217;][&#8216;birthday&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/custom fields<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $favoriteFood = $response[&#8216;registration&#8217;][&#8216;favoriteFood&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $graduated = $response[&#8216;registration&#8217;][&#8216;graduated&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/print entire array response<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;h3&gt;Response Array&lt;\/h3&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;pre&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 print_r($response);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;\/pre&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/print values<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;h3&gt;Fields Values&lt;\/h3&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8217;email: &#8216; . $email . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Name: &#8216; . $name . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Gender: &#8216; . $gender . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Facebook Id: &#8216; . $user_fb_id . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Location: &#8216; . $location . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Birthday: &#8216; . $bday . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/print custom fields<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;h3&gt;Custom Fields Values&lt;\/h3&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Favorite Food: &#8216; . $favoriteFood . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Graduated: &#8216; . $graduated . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">?&gt;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">&lt;?php<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">function parse_signed_request($signed_request, $secret)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 list($encoded_sig, $payload) = explode(&#8216;.&#8217;, $signed_request, 2); <\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \/\/ decode the data<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $sig = base64_url_decode($encoded_sig);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $data = json_decode(base64_url_decode($payload), true);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if (strtoupper($data[&#8216;algorithm&#8217;]) !== &#8216;HMAC-SHA256&#8217;)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 error_log(&#8216;Unknown algorithm. Expected HMAC-SHA256&#8217;);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 return null;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \/\/ check sig<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $expected_sig = hash_hmac(&#8216;sha256&#8217;, $payload, $secret, $raw = true);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if ($sig !== $expected_sig)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 error_log(&#8216;Bad Signed JSON signature!&#8217;);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 return null;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 return $data;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">function base64_url_decode($input)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 return base64_decode(strtr($input, &#8216;-_&#8217;, &#8216;+\/&#8217;));<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">?&gt; <\/span><\/span><\/div>\n<p>&nbsp;<\/p>\n<h3 style=\"text-align: justify;\"><span style=\"color: #3d85c6;\">Facebook registration plugin (iframe) without custom fields and only for facebook users: <\/span><\/h3>\n<p>Sometimes you might only want to allow facebook users to register on your website, you can use the attribute <b>fb_only=true<\/b> to achieve this.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background-color: #f3f3f3; color: #38761d; padding: 5px;\">\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">&lt;?php<\/span><\/div>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">$API_KEY = &#8216;463292747036958&#8217;;<\/span><\/div>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">$API_SECRET = &#8216;GET_YOUR_APP_SECRET&#8217;;<\/span><\/div>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">$redirect_URI = &#8216;http:\/\/lab.tech-and-dev.com\/facebookRegistration.php&#8217;;<\/span><\/div>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">?&gt;<\/span><\/div>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">&lt;script src=&#8221;https:\/\/connect.facebook.net\/en_US\/all.js#appId=&lt;?php echo $API_KEY; ?&gt;&amp;xfbml=1&#8243;&gt;&lt;\/script&gt;<\/span><\/div>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">&lt;div id=&#8221;fb-root&#8221;&gt;&lt;\/div&gt;<\/span><\/div>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<p><span style=\"font-family: 'Courier New',Courier,monospace; font-size: small;\">&lt;h2&gt;Without Custom Fields &#8211; Only Facebook users allowed.&lt;\/h2&gt;<br \/>\n&lt;iframe src=&#8221;http:\/\/www.facebook.com\/plugins\/registration?<br \/>\nclient_id=&lt;?php echo $API_KEY; ?&gt;&amp;<br \/>\nredirect_uri=&lt;?php echo $redirect_URI; ?&gt;&amp;<br \/>\nfb_only=true&amp;<br \/>\nfields=name,birthday,gender,location,email&#8221;<br \/>\nscrolling=&#8221;auto&#8221;<br \/>\nframeborder=&#8221;no&#8221;<br \/>\nstyle=&#8221;border:none&#8221;<br \/>\nallowTransparency=&#8221;true&#8221;<br \/>\nwidth=&#8221;530&#8243;<br \/>\nheight=&#8221;330&#8243;<br \/>\n&gt;<br \/>\n&lt;\/iframe&gt;<\/span><\/p>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<p><span style=\"font-size: small;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">&lt;?php <\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">if ($_REQUEST[&#8216;signed_request&#8217;])<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $response = parse_signed_request($_REQUEST[&#8216;signed_request&#8217;], $API_SECRET);\/\/secret<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if($response)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/Fields values<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $email=$response[&#8216;registration&#8217;][&#8217;email&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $name=$response[&#8216;registration&#8217;][&#8216;name&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $gender=$response[&#8216;registration&#8217;][&#8216;gender&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $user_fb_id=$response[&#8216;user_id&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $location=$response[&#8216;registration&#8217;][&#8216;location&#8217;][&#8216;name&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $bday = $response[&#8216;registration&#8217;][&#8216;birthday&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/print entire array response<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;h3&gt;Response Array&lt;\/h3&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;pre&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 print_r($response);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;\/pre&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/print values<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;h3&gt;Fields Values&lt;\/h3&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8217;email: &#8216; . $email . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Name: &#8216; . $name . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Gender: &#8216; . $gender . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Facebook Id: &#8216; . $user_fb_id . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Location: &#8216; . $location . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Birthday: &#8216; . $bday . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">?&gt; <\/span><\/span><\/p>\n<div style=\"font-family: 'Courier New',Courier,monospace;\"><span style=\"font-size: small;\">\u00a0<\/span><\/div>\n<p><span style=\"font-size: small;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">&lt;?php<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">function parse_signed_request($signed_request, $secret)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 list($encoded_sig, $payload) = explode(&#8216;.&#8217;, $signed_request, 2); <\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \/\/ decode the data<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $sig = base64_url_decode($encoded_sig);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $data = json_decode(base64_url_decode($payload), true);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if (strtoupper($data[&#8216;algorithm&#8217;]) !== &#8216;HMAC-SHA256&#8217;)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 error_log(&#8216;Unknown algorithm. Expected HMAC-SHA256&#8217;);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 return null;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \/\/ check sig<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $expected_sig = hash_hmac(&#8216;sha256&#8217;, $payload, $secret, $raw = true);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if ($sig !== $expected_sig)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 error_log(&#8216;Bad Signed JSON signature!&#8217;);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 return null;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 return $data;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">function base64_url_decode($input)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 return base64_decode(strtr($input, &#8216;-_&#8217;, &#8216;+\/&#8217;));<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">?&gt;<\/span><\/span><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<h3 style=\"color: #3d85c6; text-align: justify;\">Facebook registration plugin (XFBML) with custom fields:<\/h3>\n<p>If you wish to use XFBML instead of iframe, with custom fields, you can use the below example:<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background-color: #f3f3f3; color: #38761d; font-family: 'Courier New',Courier,monospace; padding: 5px;\"><span style=\"font-size: small;\">&lt;?php<\/span><br \/>\n<span style=\"font-size: small;\">$API_KEY = &#8216;463292747036958&#8217;;<\/span><br \/>\n<span style=\"font-size: small;\">$API_SECRET = &#8216;GET_YOUR_APP_SECRET&#8217;;<\/span><br \/>\n<span style=\"font-size: small;\">$redirect_URI = &#8216;http:\/\/lab.tech-and-dev.com\/facebookRegistration.php&#8217;;<\/span><br \/>\n<span style=\"font-size: small;\">?&gt;<\/span><br \/>\n<span style=\"font-size: small;\"><br \/>\n<\/span><span style=\"font-size: small;\">&lt;script src=&#8221;https:\/\/connect.facebook.net\/en_US\/all.js#appId=&lt;?php echo $API_KEY; ?&gt;&amp;xfbml=1&#8243;&gt;&lt;\/script&gt;<\/span><br \/>\n<span style=\"font-size: small;\">&lt;div id=&#8221;fb-root&#8221;&gt;&lt;\/div&gt;<\/span><br \/>\n<span style=\"font-size: small;\"><br \/>\n<\/span><span style=\"font-size: small;\">&lt;h2&gt;With Custom Fields &#8211; XFBML&lt;\/h2&gt;<br \/>\n&lt;fb:registration<br \/>\nfields=&#8221;[<br \/>\n{&#8216;name&#8217;:&#8217;name&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;birthday&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;gender&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;location&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;email&#8217;},<br \/>\n{&#8216;name&#8217;:&#8217;favoriteFood&#8217;, &#8216;description&#8217;:&#8217;Favorite Food&#8217;, &#8216;type&#8217;:&#8217;select&#8217;, &#8216;options&#8217;:{&#8216;0&#8242;:&#8217;Pizza&#8217;,&#8217;1&#8242;:&#8217;Burger&#8217;,&#8217;2&#8242;:&#8217;Hot Dog&#8217;,&#8217;3&#8242;:&#8217;Tuna&#8217;}},<br \/>\n{&#8216;name&#8217;:&#8217;graduated&#8217;, &#8216;description&#8217;:&#8217;Graduation Date&#8217;, &#8216;type&#8217;:&#8217;date&#8217;},<br \/>\n]&#8221;<br \/>\nredirect-uri=&#8221;&lt;?php echo $redirect_URI; ?&gt;&#8221;<br \/>\nwidth=&#8221;530&#8243;&gt;<br \/>\n&lt;\/fb:registration&gt;<\/span><\/div>\n<div style=\"background-color: #f3f3f3; color: #38761d; font-family: 'Courier New',Courier,monospace; padding: 5px;\"><\/div>\n<div style=\"background-color: #f3f3f3; color: #38761d; padding: 5px;\"><span style=\"font-size: small;\"><span style=\"font-family: 'Courier New',Courier,monospace;\">&lt;?php <\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">if ($_REQUEST[&#8216;signed_request&#8217;])<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $response = parse_signed_request($_REQUEST[&#8216;signed_request&#8217;], $API_SECRET);\/\/secret<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if($response)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/Fields values<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $email=$response[&#8216;registration&#8217;][&#8217;email&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $name=$response[&#8216;registration&#8217;][&#8216;name&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $gender=$response[&#8216;registration&#8217;][&#8216;gender&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $user_fb_id=$response[&#8216;user_id&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $location=$response[&#8216;registration&#8217;][&#8216;location&#8217;][&#8216;name&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $bday = $response[&#8216;registration&#8217;][&#8216;birthday&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/custom fields<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $favoriteFood = $response[&#8216;registration&#8217;][&#8216;favoriteFood&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 $graduated = $response[&#8216;registration&#8217;][&#8216;graduated&#8217;];<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/print entire array response<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;h3&gt;Response Array&lt;\/h3&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;pre&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 print_r($response);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;\/pre&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/print values<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;h3&gt;Fields Values&lt;\/h3&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8217;email: &#8216; . $email . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Name: &#8216; . $name . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Gender: &#8216; . $gender . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Facebook Id: &#8216; . $user_fb_id . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Location: &#8216; . $location . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Birthday: &#8216; . $bday . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 \/\/print custom fields<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;&lt;h3&gt;Custom Fields Values&lt;\/h3&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Favorite Food: &#8216; . $favoriteFood . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 echo &#8216;Graduated: &#8216; . $graduated . &#8216;&lt;br \/&gt;&#8217;;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">?&gt;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">&lt;?php<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">function parse_signed_request($signed_request, $secret)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 list($encoded_sig, $payload) = explode(&#8216;.&#8217;, $signed_request, 2); <\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \/\/ decode the data<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $sig = base64_url_decode($encoded_sig);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $data = json_decode(base64_url_decode($payload), true);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if (strtoupper($data[&#8216;algorithm&#8217;]) !== &#8216;HMAC-SHA256&#8217;)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 error_log(&#8216;Unknown algorithm. Expected HMAC-SHA256&#8217;);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 return null;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \/\/ check sig<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 $expected_sig = hash_hmac(&#8216;sha256&#8217;, $payload, $secret, $raw = true);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 if ($sig !== $expected_sig)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 {<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 error_log(&#8216;Bad Signed JSON signature!&#8217;);<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0 return null;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 }<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 return $data;<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">function base64_url_decode($input)<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">{<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">\u00a0\u00a0\u00a0 return base64_decode(strtr($input, &#8216;-_&#8217;, &#8216;+\/&#8217;));<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">}<\/span><br style=\"font-family: 'Courier New',Courier,monospace;\" \/><span style=\"font-family: 'Courier New',Courier,monospace;\">?&gt; <\/span><\/span><\/div>\n<p>More info about the facebook registration plugin can be found in here: <a href=\"http:\/\/developers.facebook.com\/docs\/plugins\/registration\/\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/developers.facebook.com\/docs\/plugins\/registration\/<\/a><br \/>\nExamples can be found in here: <a href=\"http:\/\/lab.tech-and-dev.com\/facebookRegistration.php\" target=\"_blank\" rel=\"noopener\">Facebook Registration Social Plugin Examples<\/a><\/p>\n<p><b>Any questions or suggestions, please post them below!<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Facebook Registration Plugin (With Custom Fields and Examples) In this post, I will show you how to implement facebook registration plugin, and I will create some examples, with custom fields, with both the iframe version and XFBML. You can check the examples directly in here: Facebook Registration Plugin Examples Scroll down for the entire source [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[90,33,94,92,93,95,91,22],"tags":[],"class_list":["post-71","post","type-post","status-publish","format-standard","hentry","category-example","category-facebook","category-facebook-api","category-facebook-app","category-facebook-registration","category-json","category-lab","category-php"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/71","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=71"}],"version-history":[{"count":1,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/71\/revisions"}],"predecessor-version":[{"id":204,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/71\/revisions\/204"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=71"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=71"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=71"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}