Cool Social Share Buttons with Share Count Script for PHP

The fastest share buttons with share count.

Last updated on
Subscribe to Internet Tips and Tools Feed

Social Network share buttons with share count can really slow down visitor's browsers that are using your website. Each button has to load the share count from the remote server of the social network. This sometimes causes pausing and freezing. Some of these buttons load asynchronously (async) with javascript and they may "claim" that they won't slow your website down. But this is not the case. Accessing the remote servers even asynchronously still causes the user to experience slowdowns.

With "Cool Social Share Buttons with Share Count Script for PHP" you can still display share buttons with share count for Google+, Facebook, Pinterest, Twitter and/or LinkedIn without slowing down your visitor's browsers because the share count is retrieved and cached on your server, so your visitor's browsers to not have to load any data from remote servers to display the share count.

Preview:

Social Buttons:
Share Count Style:
Buttons Direction:

Copy the data below to your website:






dlc_b


Download

Downloaded 0 times.
Please make a donation to reveal the download link.

Unzip the 3 files in coolsocial.zip and upload them to your website after you edit the following variables in coolsocial.php:

	/* Edit the variables below */

	$share_url = $_SERVER['HTTP_REFERER']; // The url to share will be detected by the webpage address
	//$share_url = "http://www.seabreezecomputers.com"; // Or uncomment this line to specify URL to like
	$share_text = ""; // Used on Twitter and Pinterest as description. Blank out to use current document.title
	$share_image = ""; // Used on Pinterest. Blank out to use the webpage's meta og: or itemprop tags
	
	$get_count_onclick = true; // Get count whenever a user clicks a social button
	$get_count_minutes = 720; // 0 = Don't get count every n minutes; (720 = Get count every 12 hours)
	
	$use_twitter_newsharecounts = false; // If true then register your website at newsharecounts.com

	$db_username="your_mysql_username"; 
	$db_pw="your_mysql_password";
	$server="localhost"; // Usually keep as "localhost"
	$database="your_mysql_database";

coolsocial.zip includes these files:
coolsocial.phpThe PHP script for super fast share buttons with share count
coolsocial.cssThe css style sheets for the share buttons
db.phpRequired by coolsocial.php for mysql database functions

History

1/18/2017 - Version 1.1 - Google announced that Google+ will no longer keep track of display social share count. So now the script will keep track of the Google+ shares itself in the MySQL database. Also, previously a user click on the share button was not added to the database, only what was received from the share service itself was recorded in the database. This has been changed. Now user clicks on a share button are recorded in the database as long as they are from a different IP address then the last click on the share button.

12/22/2016 - Version 1.0 - Cool Social Share Buttons with Share Count Script for PHP Created

Last updated on January 17, 2018
Created on December 22, 2016

Back to www.seabreezecomputers.com
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 8 comments.

Displaying first 50 comments.

1. Posted By: Clinton - - September 6, 2017, 1:31 am
No Database and where is this files @include_once('realsettings.php');?

2. Posted By: Jeff - - September 6, 2017, 10:27 am
Hi Clinton,

The database is automatically created on lines 188-197 of coolsocial.php. Try it! It works fine. realsettings.php is not included. That file is just in case you want to put your settings in a different file. The @ in front of include() will make sure that PHP does not display an error if it does not find the file. If you put your settings in coolsocial.php then you can comment out the line.

Jeff
www.seabreezecomputers.com/

3. Posted By: Clinton - - September 8, 2017, 4:37 pm
thank you very much

4. Posted By: Arshi - - January 17, 2018, 8:33 am
Hello,

I have implemented your share to social media code and in first look fine, but when i click on any button, at once its showing increased value above social media button, but when i check database, there is no increment or when i refresh button page no increment, i don't understand why so? anything wrong ?

Please help me.
Thanks,

5. Posted By: Jeff - - January 17, 2018, 11:32 am
Hi Arshi,

The script puts a fake increased value just for the user that clicked. So they can see their click. But the click only increases in the database if the user follows through with sharing the page. Then the count is updated according to
$get_count_minutes. So it will be a while before you see the numbers so that your server is not slowed down. That is how it works for Facebook, LinkedIn and Pinterest. Since Twitter does not keep track of share counts those are automatically entered into the database. Also, recently Google+ has decided not to keep track of share count. So I will have to change the code to automatically add that click to the database. I will create a new version soon.

Jeff
www.seabreezecomputers.com/

6. Posted By: Arshi - - January 17, 2018, 3:04 pm
Hello,
Thank you so-much for response, basically I am developing member site, and member need to login and then click on social media icons to share different content on social media and content have their content_id and members have member_id both also want to save in database, so later i can see which member how many times and which content shared on which social media, I tried many way, but I think due to ajax i m not able to figure out, I m not good in ajax, I can not send/store member_id, content_id with all other details which already in your DB, May you guide just tell me where and what should i wrote to save/store these 2 fields also in database?, I was thinking session will do the trick, but nothing happening! May you please guide/help me?

Thanks,
Arshi

7. Posted By: Jeff - - January 17, 2018, 6:15 pm
Hi Arshi,

I can try to help you. Session variables should work. Are you storing member_id in a session variable already? To use session variables, at the top of the script where you are storing the member_id in a session variable you will need to put @session_start(); for the first line of the script to start session handling. Then in coolsocial.php you will also want to add @session_start(); as the top line. You should create a new field for the social_count database. Something like: member_id BIGINT UNSIGNED

I have just uploaded a new version of coolsocial.php. So you will want to download that. It now keeps track of Google+ shares because Google+ no longer does. It also will keep track of a user click on each share button as long as it is from a different ip address.

Jeff
www.seabreezecomputers.com/

8. Posted By: Jeff - - January 17, 2018, 6:17 pm
In the latest version of coolsocial.php lines 117-124 is where the database is updated. So before that on line 116 you will want to add:

$member_id=db_escape_string($db_link, $_SESSION['member_id']);

Then to add the sanitized variable to the database. Change line 117 to look like this:

$query="UPDATE social_count SET count='$count', ip='$ip', date_updated=NOW(), member_id='$member_id'

And change line 122 and 123 to look like this:

$query="INSERT INTO social_count (url, network, count, ip, date_updated, member_id)
VALUES ('$share_url', '$network', '$count', '$ip', NOW(), '$member_id')";


Jeff
www.seabreezecomputers.com/