If you are searching for something like “how to create a facebook application using Php” then you are at the right place. Its as easy as making tea ;)

Through this code you can create your own gaming facebook application, contest facebook application etc. Many facebook users use many facebook applications and wish to create his/her own facebook application. In fact they have many new and unique ideas but they don’t know how to implement it.

So here are the simple steps to write a facebook application using Php

Step 1. you need to download the Facebook PHP SDK (software development Kit) which will allow you to create a facebook canvas and communicate with the facebook by using API.
Please download it from here facebook-php-sdk.zip.

Step 2. Upload it to your server and extract folder there.

Step 3. Now create a new php page for example index.php

Write the following code for a simple facebook application:-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
// include the SDK
require_once 'facebook-php-sdk/src/facebook.php';
 
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => 'your application ID',
'secret' => 'Your secreate key',
'cookie' => true,
));
 
//Save the user session if exist
$session = $facebook->getSession();
 
$me = null;
// Session based API call.
//check session
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
}
 
// login or logout url will be needed depending on current user state.
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
header("Location: ". $loginUrl );
die();
 
}
 
// This call will always work since we are fetching public data.
 
$ankur= $facebook->api('/ankursharma.net');
 
?>
<!doctype html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title>Test Application - 7tech.co.in</title>
<style>
body {
font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
}
h1 a {
text-decoration: none;
color: #3b5998;
}
h1 a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId   : '<?php echo $facebook->getAppId(); ?>',
session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
status  : true, // check login status
cookie  : true, // enable cookies to allow the server to access the session
xfbml   : true // parse XFBML
});
 
// whenever the user logs in, we refresh the page
FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};
 
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
<h3>Ankur</h3>
<img src="https://graph.facebook.com/naitik/picture">
<?php echo $ankur['name']; ?>
 
<div>This Application is Developed by <a href="http://www.ankursharma.net" target="_blank">Ankur Sharma - www.ankursharma.net</a></div>
</body>
</html>

Step 4. Now create a new application on facebook from here

Step5. Enter your Application ID and Secret key on the page index.php

That’s it, your application is ready just enter the php code you want to use.
Have Fun…

11 Responses so far.

  1. fat burning furnace says:

    It’s really a great and helpful piece of information. I am glad that you just shared this useful information with us. Please keep us up to date like this. Thanks for sharing.

  2. Simply wish to say your article is as amazing. The clearness in your post is simply nice and i can assume you’re an expert on this subject. Fine with your permission allow me to grab your feed to keep up to date with forthcoming post. Thanks a million and please continue the gratifying work.

  3. Kailan says:

    Well put, sir, well put. I’ll ceratnily make note of that.

  4. Gynckayably says:

    I was just looking for this information for a while. After 6 hours of continuous Googleing, at last I got it in your site. I wonder what is the Google’s issue that does not rank this type of informative sites closer to the top. Normally the top sites are full of garbage.

  5. aleltyenego says:

    It’s really a great and helpful piece of info. I’m satisfied that you just shared this useful information with us. Please stay us up to date like this. Thanks for sharing.
    nice looking site

  6. happyday67 says:

    I was looking through some of your content on this site and I think this internet site is really informative ! Retain putting up.

  7. U Tanna says:

    Hello,

    I am facing some unique problem in fb app.
    Recently we have shifted our fb app to another server
    We have installed lamp server on new server and copied all files in that new server, keeping all root directories and folder positions to be same and also changed all pointing to new servers.

    But when we tried to open app it is showing us “Failed to load source for: http://xxx.xxx.xx.xxx/xyz/?auth_token=f02eec916d6895d7ff65”

    Please help

  8. Thank you for your work. Article helped me a lot

  9. Very interesting info !Perfect just what I was looking for! “…obstacles do not exist to be surrendered to, but only to be broken.” by Adolf Hitler.