Is it possible to update database once a user shared a link in my website?
Such as,some points will be awarded to their account if they shared the link.
And
Yes, it is possible.
Example Link:
<a href="?share=YOUR+URL">SHARE TO FACEBOOK</a>
Example code to proses
if(isset($_GET['share']))
{
if(mysql_query("insert into table X() value()"))
{
//open window, you can use header('location:..') or meta redirect or another way, in this sample i'm using javascript window.open;
echo '<script>window.open("http://www.facebook.com/sharer.php?u='.urlencode($_GET['share']).'","share","width=600,height=400");</script>';
}
}
To implementing facebook "Like" button, this link maybe can help you
Update(Aug 21, 2013): Facebook's api has changed since the time this was originally posted. The way to track likes is still the same (read original answer below), but the status of the share button has changed.
The deprecation message/info. is no longer visible anywhere in the docs, but it can be seen in this bug. The share button still seems to be usable according to this doc. But there is no direct way from facebook to track a share. I'm not aware of any hacks to track shares either.
Original answer:
From Facebook docs at this link.
The Share button has been deprecated in favor of the Like button, and will no longer be supported. Please use the Like button whenever possible to drive maximum traffic to your apps.
So I'll tell you how to do it for a like button:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
// you can subscribe to events here
// edge.create event is fired only when the user likes (which means that the wall post has already happened, when the like button was clicked)
FB.Event.subscribe('edge.create',
function(response) {
alert('You liked the URL: ' + response);
// you can do some ajax call to your backend and update your database
}
);
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<fb:like href="http://example.com/fblike/"
send="true" width="450" show_faces="false"
>
</fb:like>
You can also change the word that is displayed in the like button, from like to recommend, you should try and auto-generate your like button code from this link.
I guess you are looking for this http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ You need to subscribe this event.
You do not need facebook, you could just have a Javascript AJAX call executed when someone clicks the Like button on your page. The call writes to your database. Just bin a click event to the button.