• Hi,

    I would like to ask for help in the following issue.
    I have to limit the overall successful user login number on the website. There is also membership plugin (Paid Mempeship Pro – free version), but there is no plugin or solution for this expectation.
    The reason is, that based on the concept of the author, every user can entry into the membership only 10 times.

    I checked a lot of plugin and option on the internet, but I found solution only for count and block the unsuccessful login attempts.

    Please be so kind and help me to solve the question.

    Thank you very much.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • limit to 10 successful login attempts then disable the member’s login? Why?

    Logged in user has cookie saved on browser. They can stay log in for a very long time.

    Thread Starter Webfolio Webdesign

    (@webreneszansz)

    Hi,

    This would be a part of the copyright system.

    Thank you very much.

    On some of my systems I record each login event, you could extend this code where indicated. The journal of login events will give you the information your will require to arbitrate the inevitable protests you will receive.

    // Store timestamp of each user's login, record id, ip, time
    function rcd_last_login( $user_login, $user ) {
    	global $wpdb;
    	$lrec = 'INSERT INTO '.$table_prefix.'login_journal SET lg_id='.$user->ID.', lg_ip="'.$_SERVER['REMOTE_ADDR'].'", lg_date=NULL';
    	$results = $wpdb->query($lrec);
    	if(empty($results)) {  //this error should never happen
    		echo '<p>Error recording user login.</p>';
    	}
    	//at this point count the number of entries with this ID, if >= 10 (your limit) then update the users table to prevent further logins, this will happen at the start of their last session, maybe not ideal.
    }
    add_action( 'wp_login', 'rcd_last_login', 10, 2 );

    This is the SQL to create the custom table, (substitute your table prefix for <prefix>):

    CREATE TABLE <prefix>login_journal (
      lg_id bigint(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'wp user id',
      lg_ip varchar(16) CHARACTER SET utf8 DEFAULT NULL COMMENT 'ipv4 address',
      lg_date timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'date and time of last use'
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='Log of user logins';
    ALTER TABLE <prefix>login_journal ADD PRIMARY KEY (lg_id,lg_date);
    
    • This reply was modified 3 years, 10 months ago by RossMitchell. Reason: code cleanup
    Thread Starter Webfolio Webdesign

    (@webreneszansz)

    Hi,
    Thank you very much!
    I means, that I have to add some action to remove the login right of the user, after the reach of the 10 login?

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Limit total successful login number / user’ is closed to new replies.