How to add additional login system to Webid existing one

Discussion in 'General PHP' started by Chua Bi Xia, Jan 16, 2011.

  1. Chua Bi Xia

    Chua Bi Xia New Member

    Joined:
    Aug 26, 2010
    Messages:
    15
    Likes Received:
    0
    Hi, I want to implement an additional login system for facebook (like the Webid forum where users can click on the Facebook logo to login).

    Here is my code thus far, which doesnt work. It wont load the entire page properly.
    Code:
    <!-- PHP -->
    		if ($cookie) 
    		{ 
    		$fbid = $cookie['uid'];
    		
    		
    		$query = "SELECT id, hash, suspended, password FROM " . $DBPrefix . "users
    			WHERE fb_id = '" . $fbid . "' AND suspended = 0";
    		$res = mysql_query($query);
    		$system->check_mysql($res, $query, __LINE__, __FILE__);
    
    		if (mysql_num_rows($res) > 0)
    				{
    			$password = mysql_result($res, 0, 'password');	
    			$password = md5($MD5_PREFIX . $password);
    			
    			$user_id = mysql_result($res, 0, 'id');
    			$_SESSION['WEBID_LOGGED_IN'] 		= $user_id;
    			$_SESSION['WEBID_LOGGED_NUMBER'] 	= strspn($password, mysql_result($res, 0, 'hash'));
    			$_SESSION['WEBID_LOGGED_PASS'] 		= $password;
    
    			$query = "UPDATE " . $DBPrefix . "users SET lastlogin = '" . gmdate('Y-m-d H:i:s') . "' WHERE id = " . $user_id;
    			$system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
    
    			$query = "SELECT id FROM " . $DBPrefix . "usersips WHERE USER = " . $user_id . " AND ip = '" . $_SERVER['REMOTE_ADDR'] . "'";
    			$res = mysql_query($query);
    			$system->check_mysql($res, $query, __LINE__, __FILE__);
    			if (mysql_num_rows($res) == 0)
    			{
    				$query = "INSERT INTO " . $DBPrefix . "usersips VALUES
    						(NULL, " . $user_id . ", '" . $_SERVER['REMOTE_ADDR'] . "', 'after','accept')";
    				$system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
    			}
    			else
    			{
    				$query = "UPDATE " . $DBPrefix . "usersips SET ip = '" . $_SERVER['REMOTE_ADDR'] . "' WHERE id = " . mysql_result($res, 0, 'id');
    				$system->check_mysql(mysql_query($query), $query, __LINE__, __FILE__);
    			}
    
    			if (isset($_SESSION['REDIRECT_AFTER_LOGIN']))
    			{
    				$URL = str_replace('\r', '', str_replace('\n', '', $_SESSION['REDIRECT_AFTER_LOGIN']));
    				unset($_SESSION['REDIRECT_AFTER_LOGIN']);
    			}
    			else
    			{
    				$URL = 'user_menu.php';
    			}
    
    			header('location: ' . $URL);
    			exit;
    		}
    		 } else { <!-- ENDPHP -->
          <fb:login-button>Login with Facebook</fb:login-button>
        <!-- PHP --> } <!-- ENDPHP -->
    How do I set $this->logged_in = true; (in functions_user.php) when they signed in using their account?

    Thanks!
     
  2. dragonflai

    dragonflai Active Member

    Joined:
    Jul 11, 2010
    Messages:
    570
    Likes Received:
    25
    it's more easy...
    go here: developers-facebook.com
    chose: login button and add what you nedd..

    then copy your code where you prefer inside your page.
    ;-)
     
  3. renlok

    renlok Administrator Staff Member

    Joined:
    Oct 20, 2008
    Messages:
    2,858
    Likes Received:
    330
    where are you posting this code?
     
  4. Chua Bi Xia

    Chua Bi Xia New Member

    Joined:
    Aug 26, 2010
    Messages:
    15
    Likes Received:
    0
    Hi dragonflai, But the login button only shows whether the user is logged into Facebook. It does not login to the Webid auction site? What do you mean by what you need? I've looked through the login process for Webid, & it seems to set session values then in functions_user.php it determines whether the user is logged in.

    Hi renlok, I'm adding this code in user_login.php.
     
  5. renlok

    renlok Administrator Staff Member

    Joined:
    Oct 20, 2008
    Messages:
    2,858
    Likes Received:
    330
    ok well two problems i see are
    Code:
    <!-- PHP --><!-- ENDPHP -->
    these wont do anything within a php file you need to use <?php and ?>

    From looking at http://developers.facebook.com/docs/guides/web
    Code:
    <fb:login-button>Login with Facebook</fb:login-button>
    This also wont work in a php file this needs to be in the template file you also need the javascript to go with it
    Code:
    <script src="http://connect.facebook.net/en_US/all.js"></script>
          <script>
             FB.init({ 
                appId:'YOUR_APP_ID', cookie:true, 
                status:true, xfbml:true 
             });
          </script>
    and you need to of registered your site with facebook http://developers.facebook.com/setup/


    You will need some way of letting users link there webid account with their facebook account and probably also a way for users to register using their facebook account, the first link should have all the info needed to do this
     
    Chua Bi Xia likes this.
  6. Chua Bi Xia

    Chua Bi Xia New Member

    Joined:
    Aug 26, 2010
    Messages:
    15
    Likes Received:
    0
  7. Leif Glass

    Leif Glass New Member

    Joined:
    Nov 14, 2011
    Messages:
    5
    Likes Received:
    1
    Solved?

    Can you tell me how you solved this? I am trying but the pieces are not making the puzzle.
     
    OscarMR likes this.
  8. OscarMR

    OscarMR New Member

    Joined:
    Sep 13, 2018
    Messages:
    6
    Likes Received:
    0
    can you share your mod for facebook login?
     

Share This Page