Cool Social Share Buttons with Share Count Script for PHP

The fastest share buttons with share count.

Last updated on
((( spellific )))
Practice spelling while playing a fun word game!
Click here to play
Speech Recognition Anywhere
  • Type emails with your voice
  • Write documents with your voice
  • Control the Internet with your voice
  • Chrome Extension
Reconocimiento de voz en cualquier lugar
  • Escribe correos electrónicos con tu voz
  • Escribe documentos con tu voz
  • Controla la Internet con tu voz
  • Extensión de Chrome
Spracherkennung Allerorts
  • Geben Sie E-Mails mit Ihrer Stimme ein
  • Schreiben Sie Dokumente mit Ihrer Stimme
  • Steuern Sie das Internet mit Ihrer Stimme
  • Chrome-Erweiterung
Reconnaissance de la parole
  • Tapez des e-mails avec votre voix
  • Écrivez des documents avec votre voix
  • Contrôlez l'Inernet avec votre voix
  • Extension Chrome
Riconoscimento vocale ovunque
  • Digita e-mail con la tua voce
  • Scrivi documenti con la tua voce
  • Controlla Internet con la tua voce
  • Estensione Chrome
どこでも
音声認識
  • あなたの声で文書を書く
  • あなたの声でメールを入力してください
  • 音声でインターネットをコントロール
  • Chrome拡張機能
语音识别
无处不在
  • 用你的声音写文件
  • 用您的声音输入电子邮件
  • 用你的声音控制互联网
  • Chrome 扩展程序
語音識別
無處不在
  • 用你的聲音寫文件
  • 用您的聲音輸入電子郵件
  • 用你的聲音控制互聯網
  • Chrome 擴展程序
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)
	
	/* Leave $fb_access_token blank for the script to just keep track of share button clicks
		or to get real Facebook share count create an app for your website at 
		https://developers.facebook.com/apps
		Find your app access token at 
		https://developers.facebook.com/tools/accesstoken/
		Or use "your_app_id|your_app_secret" for $fb_access_token.
	*/
	$fb_access_token = ""; // "your_app_id|your_app_secret"
	
	$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

February 17, 2022 - Version 1.1d - Facebook now requires that website owners use an app access_token or app_id and app_secret to get share counts. The script has been updated with $fb_access_token variable. Leave blank for the script to just count clicks on the share button.

March 8, 2021 - Version 1.1c - Bug Fix - Put inet_pton() inside of escape_string because on the outside mysql sometimes has an error because inet_pton() sometimes puts an unescaped single quote in the string.

2/19/2018 - Version 1.1b - On February 7, 2018 LinkedIn announced that they are no longer keeping track of or displaying share counts for LinkedIn. So now the script will keep track of the LinkedIn shares itself in the MySQL database by keeping count of the clicks on the LinkedIn share button. Also, added PHP curl as an alternative to get share count from Facebook and Pinterest in case of file_get_contents() not working such as getting the error: PHP Warning: file_get_contents(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0.

2/17/2018 - Version 1.1a - Fixed a number of bugs including adding $get_count_minutes to the global variable in check_network() function and not updating the mysql database if the last share count in the database is the same as the share count retrieved from the share network. Also if the count is updated or added to the database because it is the first time or because $get_count_minutes as elapsed then it won't use the ip address of the user visiting so that they can still click on the share button.

1/18/2018 - 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 February 17, 2022
Created on December 22, 2016

((( spellific )))
Practice spelling while playing a fun word game!
Click here to play
Speech Recognition Anywhere
  • Type emails with your voice
  • Write documents with your voice
  • Control the Internet with your voice
  • Chrome Extension
Reconocimiento de voz en cualquier lugar
  • Escribe correos electrónicos con tu voz
  • Escribe documentos con tu voz
  • Controla la Internet con tu voz
  • Extensión de Chrome
Spracherkennung Allerorts
  • Geben Sie E-Mails mit Ihrer Stimme ein
  • Schreiben Sie Dokumente mit Ihrer Stimme
  • Steuern Sie das Internet mit Ihrer Stimme
  • Chrome-Erweiterung
Reconnaissance de la parole
  • Tapez des e-mails avec votre voix
  • Écrivez des documents avec votre voix
  • Contrôlez l'Inernet avec votre voix
  • Extension Chrome
Riconoscimento vocale ovunque
  • Digita e-mail con la tua voce
  • Scrivi documenti con la tua voce
  • Controlla Internet con la tua voce
  • Estensione Chrome
どこでも
音声認識
  • あなたの声で文書を書く
  • あなたの声でメールを入力してください
  • 音声でインターネットをコントロール
  • Chrome拡張機能
语音识别
无处不在
  • 用你的声音写文件
  • 用您的声音输入电子邮件
  • 用你的声音控制互联网
  • Chrome 扩展程序
語音識別
無處不在
  • 用你的聲音寫文件
  • 用您的聲音輸入電子郵件
  • 用你的聲音控制互聯網
  • Chrome 擴展程序
Back to www.seabreezecomputers.com
Subscribe to Internet Tips and Tools Feed        

User Comments

There are 18 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/


9. Posted By: Arshi - - January 27, 2018, 6:33 pm
Hello,

I have modified code as u said for adding member id, Now problem is, when member click on Facebook share, twitter or any icon, its automatically update database without clicking on any social media post button/link, i want database update only when content shared on social media successfully, currently click on any icon its update even u don't click on any social media "POST" link/button.

Any solution for it? I will be Thankful to you!

Arshi

10. Posted By: Sidharth - - May 10, 2019, 1:16 am
On sharing it to fb
It is showing 'feature isn't available right now, an error occur while processing this request.


It's also showing error on posting it to LinkedIn

11. Posted By: Jeff - - May 10, 2019, 8:51 am
Hi Sidharth,

In googling the error the results say that the error occurs when the link you try to share is not live. See this post: stackoverflow.com/questions/54033240/how-to-solve-error-sorry-this-feature-isnt-available-right-now-an-error-occu

Jeff
www.seabreezecomputers.com/

12. Posted By: Sidharth - - May 11, 2019, 8:46 am
Very very thanks for replying ,
Sorry for bothering you,
Fault is mine , I was doing it wrong
Your code was just amazing
Thanks

13. Posted By: Mydevelopers - - February 15, 2022, 11:31 pm
I had used the code completely same as per the zip file i had downloaded but the count is not increasing in the database what could be the issue

14. Posted By: Jeff - - February 16, 2022, 12:22 pm
Hi  Mydevelopers,

Which button are you pressing that is not updating? Check the website folder you have the script in to see if PHP has an error_log file. It may contain helpful information. Please provide a website link so that we can look at it and test it.

Jeff
http://www.seabreezecomputers.com/

15. Posted By: Mydevelopers - - February 16, 2022, 8:42 pm
Hello Jeff,

As I checked no error log was there.

Any of the button.

For facebook i am doing like below
Once i click to facebook share button it takes me to facebook where i can see the post which i am sharing after click to share / submit button and the post was shared successfully after that window closed automatically and if i check the database the count not increasing i had waited for the time i had set on the file which is 240 or 60 in place of 720.

DO i need to register the website in any third part site also ?

16. Posted By: Jeff - - February 17, 2022, 3:47 pm
Hello Mydevelopers,

I now updated the script (Version 1.1d) to more easily allow you to use a facebook access_token or to just let the script keep track of clicks on the share button. You can download the updated script at the website. Keep in mind that the script does not update the share count if the same user with the same ip address clicks on the share button more than once.

17. Posted By: MOD13 - - February 14, 2023, 7:12 pm
After installing pages & completing changes, when clicking link to count via TWITTER data is deleted after 2nd click. Sometimes clicks don't update to database.

Like to get help thanks

18. Posted By: Jeff - - February 14, 2023, 10:05 pm
Hi MOD13,

The script is designed to not keep increasing the share count if the same user is clicking the same button again. Share counts are only supposed to count once per user. When a user tries to share the same link twice it will show the number increase to the user but the database will not increase so when the page is refreshed it will show the previous number. If you are trying to artificially inflate the share count then you can just edit the MySQL database. If you want the database Twitter share count to keep increasing even though a user has already shared then change line 253 to this:

if (isset($_POST['click']))

Jeff
http://www.seabreezecomputers.com/