Login One Session

Discussion in 'aMember Pro v.4' started by sc0tsman, Dec 2, 2013.

  1. sc0tsman

    sc0tsman Member

    Joined:
    Nov 25, 2009
    Messages:
    119
    I used to have this plugin working on my old site using amember v3 however on my new site this does not work. Also on my WP site I have amember set to protect whole blog is it possible to have one page unprotected?

    Please look at this script and tell me if I am doing anything wrong. I am willing to pay a small amount if additional work is required as I feel amember single login plugin does not match my requirements .

    Code:
        <?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 , 2 );
            add_filter( 'auth_cookie', 'cclo_set_key' , null , 4 );
        }
        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

Share This Page