Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[FB CONNECT] Facebook SDK PHP [All CMS][Not beginner friendly]

Status
Not open for further replies.
Joined
Feb 18, 2012
Messages
779
Reaction score
247
Hi today i'm going to show you how to set up facebook SDK PHP. :):

Everything past this line is not for people who don't know basic php / there way around a CMS so if you don't know how to code wait until people see this and release it for your CMS.

Download the SDK from github here (Only download /src)



Now create a /facebook/API/ directory and place the base_facebook.php + crt file + the facebook.php in there.

Now create a file in just /facebook/ with the name either index or facebook, whatever you want to point the URL too.

Open that up and put something in there along the lines of this (you can change this around however you want, this is just a basic login / register function)

PHP:
<?php

mysql_connect("localhost","root","MYSQL PASS HERE");
mysql_select_db("DB NAME HERE");

require_once("API/facebook.php"); // Change file if you have a different way of including files or want more files

define('APP_ID', 'YOUR APP ID'); // APP ID from you app page
define('APP_SECRET', 'YOUR APP SECRET'); // APP Secret from your app page

$facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_SECRET, 'cookie' => true));

$profile = $facebook->api('/me');

$userq = mysql_query('SELECT * FROM users WHERE facebook_id = "'.$profile['id'].'"') or die(mysql_error());
$users = mysql_fetch_array($userq);
$num = mysql_num_rows($userq);

$fbname = "NewUser";

if($num > 0){

// Login function here or starting session
// header("location:/redirect");

} else {

// Login & Register a user here and redirect to wherever
// header("location:/redirect");

}

?>

Here's the HTML code for the button, also change these settings (most are labelled).
PS - This is if you're using habbos css/js so i dunno if your not..
Code:
<div id="rpx-login">
                <div>
<div id="fb-root" class=" fb_reset"><script async="" src="http://connect.facebook.net/en_US/all.js"></script><div style="position: absolute; top: -10000px; height: 0px; width: 0px;"><div><iframe name="fb_xdm_frame_http" frameborder="0" allowtransparency="true" scrolling="no" aria-hidden="true" title="Facebook Cross Domain Communication Frame" tab-index="-1" style="border: none;" src="http://static.ak.facebook.com/connect/xd_arbiter.php?version=18#channel=f1f5c0edcc&origin=http://hebbo.ca&channel_path=%2Findex%3Ffb_xd_fragment%23xd_sig%3Df1b79d2adc%26"></iframe><iframe name="fb_xdm_frame_https" frameborder="0" allowtransparency="true" scrolling="no" aria-hidden="true" title="Facebook Cross Domain Communication Frame" tab-index="-1" style="border: none;" src="https://s-static.ak.facebook.com/connect/xd_arbiter.php?version=18#channel=f1f5c0edcc&origin=http://hebbo.ca&channel_path=%2Findex%3Ffb_xd_fragment%23xd_sig%3Df1b79d2adc%26"></iframe></div></div><div style="position: absolute; top: -10000px; height: 0px; width: 0px;"><div></div></div></div>

			<script type="text/javascript">
    window.fbAsyncInit = function() {
        Cookie.erase("fbsr_183096284873");
        FB.init({appId: 'APPID', status: true, cookie: true, xfbml: true});
        if (window.habboPageInitQueue) {
            // jquery might not be loaded yet
            habboPageInitQueue.push(function() {
                $(document).trigger("fbevents:scriptLoaded");
            });
        } else {
            $(document).fire("fbevents:scriptLoaded");
        }

    };
    window.assistedLogin = function(FBobject, optresponse) {
        
        Cookie.erase("fbsr_183096284873");
        FBobject.init({appId: 'YOURAPPID', status: true, cookie: true, xfbml: true});

        permissions = 'user_birthday,user_about_me,email';
        defaultAction = function(response) {

            if (response.authResponse) {
                fbConnectUrl = "LINK TO YOUR FACEBOOK/INDEX LOGIN";
                Cookie.erase("fbhb_val_183096284873");
                Cookie.set("fbhb_val_183096284873", response.authResponse.accessToken);
                Cookie.erase("fbhb_expr_183096284873");
                Cookie.set("fbhb_expr_183096284873", response.authResponse.expiresIn);
                window.location.replace(fbConnectUrl);
            }
        };

        if (typeof optresponse == 'undefined')
            FBobject.login(defaultAction, {scope:permissions});
        else
            FBobject.login(optresponse, {scope:permissions});

    };

    (function() {
        var e = document.createElement('script');
        e.async = true;
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
</script>

<a class="fb_button fb_button_large" onclick="assistedLogin(FB); return false;">
    <span class="fb_button_text">Login with Facebook</span>
</a>
                </div>

                <div>


<div id="rpx-signin">
    <a class="rpxnow" onclick="return false;" href="#yourextras?">More ways to login</a>
</div>                </div>

            </div>

Almost forgot, you need your own facebook app, so i'l show you how! :thumbup1:

Click to show your current apps and the create an app button.

Click the "Create new app" button to start.

Now just type in your basic info..
JaydenC - [FB CONNECT] Facebook SDK PHP [All CMS][Not beginner friendly] - RaGEZONE Forums

Now your going to need to edit the Site URL, to your facebook index/login url. (/facebook/index.php or /facebook/facebook.php)
JaydenC - [FB CONNECT] Facebook SDK PHP [All CMS][Not beginner friendly] - RaGEZONE Forums

Covered app secret + email.

Now just copy your APP ID + APP SECRET and put it in the files that require editing (not anything in /api).

The outcome
JaydenC - [FB CONNECT] Facebook SDK PHP [All CMS][Not beginner friendly] - RaGEZONE Forums

A working facebook login!

Note : Like + Rep to show respect to the creator of the tut :love:

PS, you need cURL enabled for this to work. If you code PHP you can have a nice choose name function / choose pass aswell. For now the $username variable generates random usernames like User1256 and then they can change there username in-client if your using R63B otherwise code a if($_POST['form'] etc.
 
Last edited:
Joined
May 8, 2010
Messages
1,902
Reaction score
669
Right sir, this is very good and tidy.
I also found that when you change your username in-client, you cant login anymore x]

Gonna test this out, and work on it for Uber CMS x] (Me no like Rev)
 
Joined
Feb 18, 2012
Messages
779
Reaction score
247
Right sir, this is very good and tidy.
I also found that when you change your username in-client, you cant login anymore x]

Gonna test this out, and work on it for Uber CMS x] (Me no like Rev)

Not sure, i'l do a basic web-based change username script if needed?

Make sure you look over the main php, cause you need to add your own register/login functions like
$users->adduser(Jayden,Motto,Look); etc - this wont work btw
 
Joined
May 8, 2010
Messages
1,902
Reaction score
669
Not sure, i'l do a basic web-based change username script if needed?

Make sure you look over the main php, cause you need to add your own register/login functions like
$users->adduser(Jayden,Motto,Look); etc - this wont work btw

Yeah, casn you make a web based change username script then? I have some sort of example in my mind on how to do it, but meh.

Im looking over the main php and trying to figure it all out, i only know a small amount of php, but just learning x]
 
Joined
May 8, 2010
Messages
1,902
Reaction score
669
Hmm, considering that I might just do one quickly for uber

ok heres ur script

PHP:
<form method="post" action="">
New username : <input type="text" name="box"/>
</form>
<?php

if($_POST['box']){
$username = "{username}"; // {username} is revCMS, not sure about ubers syntax.
$safe = mysql_real_escape_string($_POST['box']);
mysql_query("UPDATE users SET username="'.$safe.'" WHERE username="'.$username.'"");
}else{
// nothing?
}

?>

just add that somewhere in ur site

change the $username="{username}"; to $username="%habboName%"; if ur using uberCMS

Mm, okay, and the user sytax is %habboname% i think

Error already x[

Parse error: syntax error, unexpected ''.$safe.'' (T_CONSTANT_ENCAPSED_STRING) in C:\inetupub\wwwroot\rename.php on line 9
 
topkek amirite??
Joined
May 16, 2009
Messages
751
Reaction score
696
Undefined index: box in C:\inetupub\wwwroot\includes\tpl\new-name.tpl on line 14

Got bored.

PHP:
<?php
if(isset($_POST['username'])){
	if(empty($_POST['username']) || $_POST['username'] == "") {
		echo "<b>Oops!</b> Username cannot be empty.";
	} else {
		$username = "{username}"; // {username} is revCMS, not sure about ubers syntax.
		$safe = mysql_real_escape_string($_POST['username']);
		
		$check = mysql_result(mysql_query("SELECT COUNT(*) FROM users WHERE username = '" . $safe . "'"), 0);
		if($check != 0) {
			echo "<b>Oops!</b> This username is already taken.";
		} else {
			mysql_query("UPDATE users SET username = '" . $safe . "' WHERE username = '" . $username . "'");
			echo "<b>Thank you.</b> Your username has been changed.";
			
			// Update the session if needed (I don't know how rev/uber have their sessions.)
		}
	}
}
?>

<form method="post" action="">
New username: <input type="text" name="username" placeholder="New username"/><br />
<input type="submit" value="Change username" />
</form>

Completely untested.
 
☮TAKU????
Member
Joined
Nov 16, 2009
Messages
866
Reaction score
580
For the username creation thingy you can use $fbdata['username'] to make it more like them. Plus you should never trust users input, not even facebooks API :p
 
Joined
Feb 18, 2012
Messages
779
Reaction score
247
For the username creation thingy you can use $fbdata['username'] to make it more like them. Plus you should never trust users input, not even facebooks API :p

And you think FACECBOOK wouldn't have a some sort of incredible impossible to beat username safety script? the thing you should be worried about is admin-etc.

PS : I don't think you can take username/real name anymore because they have a security thing. You can however get there "aboutme" + email i believe. Its all .
 
Experienced Elementalist
Joined
Oct 17, 2008
Messages
293
Reaction score
64
Good thing if you are using BcStorm is you can give them usernamechange and they are then aloud to change there username once.
 
Experienced Elementalist
Joined
Oct 17, 2008
Messages
293
Reaction score
64
yep

did u get it working?

I haven't tried using this FB script yet might start doing it in a minute then I'll see what I can do.

I get stuck here?

 
Last edited:
The one and only!
Member
Joined
Nov 24, 2008
Messages
2,529
Reaction score
1,435
Good thing if you are using BcStorm is you can give them usernamechange and they are then aloud to change there username once.
You don't need an emulator to do that. You can just code the function into the CMS.
 
Status
Not open for further replies.
Back
Top