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 SessionDescription: This plug-in can limit simultaneous login.Author: COLORCHIPSVersion: 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);}
Now been running this for about 10 days and very buggy, the "delete other session" part does not work at all.
If someone could look at my initial script "Login Only 1 Session" that would be great as it worked perfect on my old site.