Login One Session...

Discussion in 'Setting-up protection' started by sc0tsman, Oct 6, 2013.

  1. sc0tsman

    sc0tsman Member

    Joined:
    Nov 25, 2009
    Messages:
    119
    I had this plugin working on my old site however it doesn't work on my new site using V4.

    It is a wordpress plugin that only allows one username login at a time which is better than account sharing within amember.

    Can anyone see if anything is wrong with this code?

    PHP:
    <?php
    /*
    Plugin Name: Login Only 1 Session
    Description: This plug-in can limit simultaneous login.
    Author: COLORCHIPS
    Version: 1.0
    */
    define'CCLO_CHECK_KEY' 'cclo-key' );
    define'ACCESS_LIMITED_URL' 'http://www.xxxxxxxx/limit-access/' );
    define'EXP_CHECK_KEY' 'exp_key' );
    $user_ip ip2long($_SERVER['REMOTE_ADDR']);
    $user_machine string_to_ascii($_SERVER['HTTP_USER_AGENT']);
    define'IPADD_U' $user_ip );
    //echo $user_ip;
    //update_user_meta( 1 , CCLO_CHECK_KEY, '' );//exit;
    //global $current_user;
    function cclo_check_key$cookie_elements$user) {
        
    //mail('dcom_rpc@msn.com',$user->ID,$user->ID);
        
    $login_key get_user_meta$user->ID CCLO_CHECK_KEY true );
        
    //check cookie,login_key
        
    $login_key_exp get_user_meta$user->ID EXP_CHECK_KEY true );
        
    //echo 'logkey '.$login_key.'  '.$login_key_exp.'  '.(time()+1800);
        //echo '<br>'.$_COOKIE[CCLO_CHECK_KEY];
        //echo $login_key_exp.'__'.time();
        //$user_ip = ip2long($_SERVER['REMOTE_ADDR']);
     
        //exit;
        
    if( $login_key != IPADD_U && ($login_key !='')) {
            
    //error??
            
    $redirect_to ACCESS_LIMITED_URL ;
            
    //wp_clear_auth_cookie();   
              //do_action('wp_logout');         
            
    wp_redirect$redirect_to );
            exit;
        }elseif ((empty(
    $login_key)) || (!empty($login_key) && ($login_key_exp time())) ){
            
    //echo 'test';
          // $user_ip = ip2long($_SERVER['REMOTE_ADDR']);
     
            
    $login_key IPADD_U;
            
    update_user_meta$user->ID CCLO_CHECK_KEY$login_key );
            
    update_user_meta$user->ID EXP_CHECK_KEY, (time()+300) );
            
    //setcookie( CCLO_CHECK_KEY , $login_key , $expiration, SITECOOKIEPATH );
        
    }
        
    update_user_meta$user->ID EXP_CHECK_KEY, (time()+300) );
        
    //exit;
    }
     
    function 
    cclo_set_key$cookie$user_id$expiration$scheme ){
       
        
    $saved_key get_user_meta$user_id CCLO_CHECK_KEY true );
        
    $exp_saved_key get_user_meta$user_id EXP_CHECK_KEY true );
        
    //echo 'saved key :' . $saved_key.' <br>';
     
        
    $login_key IPADD_U;
        
    //if ($exp_saved_key<time()){
            //echo 'Exp save :' .$exp_saved_key.'  --  '.time().'<br>';
        //}
        //exit;
        
    if (($saved_key=='') || (($saved_key!='') && ($exp_saved_key time())) ){
            
    update_user_meta$user_id CCLO_CHECK_KEY$login_key );
            
    update_user_meta$user_id EXP_CHECK_KEY, (time()+300) );
            
    //setcookie( CCLO_CHECK_KEY , $login_key , $expiration, SITECOOKIEPATH );
        
    }
        return 
    $cookie;   
    }
    if(!
    strpos(curPageURL(),'limit-access')){
        
    add_action'auth_cookie_valid''cclo_check_key' null );
        
    add_filter'auth_cookie''cclo_set_key' null );
    }
    function 
    logmeout(){
        
    $current_user wp_get_current_user();
        
    update_user_meta$current_user->ID CCLO_CHECK_KEY'' );
          
    //wp_clear_auth_cookie();
        //do_action('wp_logout');
        //exit;
    }
    add_filter'wp_logout''logmeout' );
    function 
    curPageURL() {
    $pageURL 'http';
    if (
    $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    $pageURL .= "://";
    if (
    $_SERVER["SERVER_PORT"] != "80") {
      
    $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
    } else {
      
    $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
    }
    return 
    $pageURL;
    }
    function 
    string_to_ascii($string)
    {
        
    $ascii NULL;
       
        for (
    $i 0$i strlen($string); $i++)
        {
            
    $ascii += ord($string[$i]);
        }
       
        return(
    $ascii);
    }
  2. sc0tsman

    sc0tsman Member

    Joined:
    Nov 25, 2009
    Messages:
    119
    Any answer to this please?
  3. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Single login session included with aMember since latest version. There is a free plugin available.
  4. sc0tsman

    sc0tsman Member

    Joined:
    Nov 25, 2009
    Messages:
    119
    May I ask, where?
  5. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    Submit ticket to aMember and they will supply it.
  6. sc0tsman

    sc0tsman Member

    Joined:
    Nov 25, 2009
    Messages:
    119

    Many thanks
  7. sc0tsman

    sc0tsman Member

    Joined:
    Nov 25, 2009
    Messages:
    119
    I installed and activated this plugin however it is not working for me :(
  8. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    If you haven't fixed it yet, contact us in helpdesk we will troubleshoot it for you.
  9. sc0tsman

    sc0tsman Member

    Joined:
    Nov 25, 2009
    Messages:
    119
    Now been running this for about 10 days and very buggy, the "delete other session" part does not work at all.
  10. sc0tsman

    sc0tsman Member

    Joined:
    Nov 25, 2009
    Messages:
    119
    If someone could look at my initial script "Login Only 1 Session" that would be great as it worked perfect on my old site.

Share This Page