Jump to content

Session Variable help needed (Facebook Connect)


stitchmedia

Recommended Posts

I need a little help with my implementation of Facebook Connect.

My site login page has 2 login options

1.  Standard login - allows entry of username and password and redirect the user to the restricted page

2.  Facebook Connect - allows a user to login using their Facebook account.

 

I can get both logins to work but I need the Facebook Connect login to set some session variables (one being 'kt_login'id').  The value of the session is a userid (tblMembers.MemberID) which identifies the user.  I can not get it to populate.  Here is my code:

 

<?php
global $api_key,$secret;
$fb=new Facebook($api_key,$secret);
$fb_user=$fb->get_loggedin_user();
if($fb_user) {
//Query your database to see if the $fb_user exists
	$conn_Fallen = new KT_connection($Fallen, $database_Fallen); // you can use whatever database connection and query techniques you normally would use.

	//you'll have to modify this query for your own database
    $query="select MemberID, Username, FacebookID, AccessLevel from tblMembers where FacebookID=$fb_user";
    
    $result=mysql_query($query,$Fallen);

//if you get a row back then : Log the user into your application by setting a cookie 
//or by setting a session variable or whatever other means you like or use.
// then send off to the logged in user page:        
if($result && @mysql_num_rows($result)==1) {
    	$_SESSION['authorized']='true';
	$_SESSION['kt_login_id']=$query['MemberID'];
    	//you can also optionally set their user id (your sites id) in the session as well if you need to  	
    	//After setting session values, forward them off to the Logged in User page.
    	header("Location: http://www.fallenindustries.tv/newsite/index.php");
} else {
	//user is logged into FB and has authorized yoursite.com for connect. But
	//we don't have their fb_user id stored on yoursite.com database yet.		
	//so send them to the Connect Account page so they can either link up with an 
	//existing account or create a new one.
	header("Location: http://www.fallenindustries.tv/newsite/connectAccount.php");
}
}
?>

 

I have used this line to set the session variable:

 

$_SESSION['kt_login_id']=$query['MemberID'];

 

but when I get to the logged in page all that is populated in the session is an 's'.

 

Any suggestions on where I'm going wrong?

 

Thanks

 

Dave

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.