Translations

Know another language? Translate this tutorial!

Facebook share button (PHP)

Favourite 53 favourites
Tutorial written by stctrOriginally published on 15th, March 2014 - 1 revision

Hi, sorry for my bad English and grammar.

How to make a Facebook share button for your Construct2 games;

What you need:
1. You need a website that runs PHP.
2. You have to upload share.php on your server.
3. You got a facebook share button on your game.

share.php code :

    <?php
    $score = $_GET["score"];
    $scorex = explode(":", $score);
    $highscore = $scorex[0];
    ?>
    <html>
    <head>
    <title>Weebe Jello Jumper HighScore</title>
    <meta property="og:title" content="Highscore on Jello Jumper is <?echo $highscore;?>!"/>
    <meta property="og:image" content="http://weebe.nl/jellojumper/jello.png"/>
    <meta property="og:site_name" content="Weebe Game Studio"/>
    <meta property="og:description" content="<?echo $highscore;?> is mine new highscore on Jello Jumper! How far do you think you can get? Try it for free!"/>	
    </head>
    <body>
    <meta http-equiv="refresh" content="0;URL=http://www.yoursite.com" />
    </body>
    </html>

Change the information like titles, image paths, descriptions etc. for your own game.

The .php code above will show this on facebook :


In your game add the Browser object and this event:
Open full size image

Change the number 5000 with your own score, it could be something like : Webstorage.LocalValue("highscore"). Or else it will post 5000 every time.

The random number system is for Facebook cache, if the URL is already used in Facebook it will get the title etc from the cache not your website. That's why we give Facebook a new URL with random numbers every time.

It works with CocoonJS, i used it in my game for a demo check out :
https://play.google.com/store/apps/details?id=com.JelloJumper.WeebeStudio

I hope this tutorial will help you guys, Enjoy!

Unlock your full gamedev potential

Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!

View deals

Plus, it's got a lot of additional features that will help you save time and make more impressive games!

Congratulations on finishing this tutorial!

Did you learn a lot from it? Share it now with your friends!

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

Comments

1
hd4real 398 rep

Hi, I tested this but highscore shows the 5000 from the event code and not the 38 highscore from my game. What did I do wrong?

Saturday, March 15, 2014 at 9:27:41 PM
1
Lordshiva1948 44.3k rep

highscore is not working properly could be my mistake not sure but, thanks for sharing

Sunday, March 16, 2014 at 6:21:17 AM
1
ArcadEd 22.2k rep

This may work with cocoonJS as we'll. thanks, I will try it.

Sunday, March 16, 2014 at 5:31:22 PM
1
bremen 2,645 rep

@ArcadED did you manage to get this to work on CocoonJS? I'm very interested in this I'm working on mine now.

Monday, March 17, 2014 at 5:49:39 AM
1
stctr 6,141 rep

Go to "www.facebook.com/sharer/sharer.php?u=http://www.gocrazybee.com/share.php?score=" & "5000" & ":" & random(1,10) in a new window ("NewWindow")

Instead of 5000 you have to write something like,
Go to "www.facebook.com/sharer/sharer.php?u=http://www.yoursite.com/share.php?score=" & Webstorage.LocalValue("highscore") & ":" & random(1,10) in a new window ("NewWindow")

Webstorage.LocalValue("highscore") Here you give the right number to post.

This system works with CocoonJs.

Demo:
play.google.com/store/apps/details?id=com.JelloJumper.WeebeStudio

Monday, March 17, 2014 at 9:00:07 PM
1
amkp 2,165 rep

Nice tip, thanks! And for tweeter ? ^^

Tuesday, March 18, 2014 at 12:34:43 PM
1
diegocaetanop 387 rep

error syntax please view screenshot http : / / prntscr .com/32p8x2

Friday, March 21, 2014 at 5:22:23 AM
1
mrnannings 3,508 rep

Can you make a plugin like this for c2

Friday, March 21, 2014 at 7:48:08 AM
2
stctr 6,141 rep

@amkp

I will submit a tutorial for tweeter today.

@diegocaetanop

Delete : in a new window ("NewWindow")
That line will be added automatically by Construct2. :)

@mrnannings

I can't code plugins sorry.

Friday, March 21, 2014 at 9:31:04 AM
2
amkp 2,165 rep

"I will submit a tutorial for tweeter today."

Cool !

Sunday, March 23, 2014 at 9:47:12 AM
1
stctr 6,141 rep
"I will submit a tutorial for tweeter today."

Cool !
quoted from amkp

Just made a tutorial for twitter :
www.scirra.com/tutorials/927/twitter-share-tweet-button-browser-object

Sunday, March 23, 2014 at 10:56:29 PM
1
bremen 2,645 rep

Great Job! Thanks for the Tutorial

Sunday, March 23, 2014 at 11:19:43 PM
1
Pariunos 853 rep

Can the share.php file be hosted on google drive or does it have to be an actual server?

Friday, March 28, 2014 at 9:05:39 AM
1
gfigueroa 2,209 rep

Thanks for the tutorial, it works great with Windows 8 PC, but I have not been able to make it work with Windows Phone, has anyone tried it with Windows Phone?

Saturday, March 29, 2014 at 5:35:48 PM
1
irina 6,924 rep

@stctr

Thanks for this one!

Any chance of showing show how to set a simple "like" button?

Monday, March 31, 2014 at 9:27:24 AM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.