Facebook social plugins are widely used to promote websites, blog posts etc. In this post I am going to tell you how to dynamically create a Facebook share button in PHP and how to populate and open the Facebook share popup so the user can stay on the same page while sharing to Facebook. Meta tags will be used to populate this.

Let’s get on with it then

Lets start with the Facebook share button. To create a Facebook share button you need two things, first is the share button image and second is the unique URL that is used by facebook to fetch the data from. For a unique URL we’ll use fbsharepage.php with the query string parameter that is the id to make it unique, the id can be a number or a string and if you’re using a database then you can use a primary key as an id as it’s always unique.