This topic is locked

After x user registrations, the link register should be hidden

6/24/2021 8:26:26 AM
PHPRunner General questions
A
Andreas G. author

Is that possible ?
Should only work with self-registration.

Example: After 100 registered users, the link register in the login.php should be hidden

Thanks for a snippet of code or your help

Andy

fhumanes 7/7/2021

Hello:

To hide the new user records button you have to put this line in JavaScript:

$('[data-itemid="loginform_register_link"]').hide();

Greetings,
fernando

A
Andreas G. author 7/7/2021

HI fhumanes

We got it wrong.
Only after 100 registered users should the register no longer be visible.
With the code, it is always hidden.

I am capable of learning, but it also doesn't work with the option:

Check if specific record exists.

If a user ID in db_users is greater than 99 then hide "registration".

I must have just one mistake in my thinking

Translated with Google
greetings from Germany

A
acpan 7/7/2021

As far as I know, the only way you can restrict the registration is by querying the database, one way is to include an external php script in your login form, that query the database, and if the count exceeds your predefined limit, redirects the user to another page.

The external script should be independent of PHP dbcommon script, as PHPRunner dbommon only allows to be used when a user has already logged in.

There are many mysql class scripts that you can use in the internet. prepare it and include that script in your login form and thwt should solve your issue.

Hope it helps.

A
Andreas G. author 7/7/2021

Thanks for the feedback !
I will now integrate (try) a query of the ID via an additional script and redirect to another login page when the desired number of users is reached
Translated with Google

admin 7/7/2021

The external script should be independent of PHP dbcommon script, as PHPRunner dbommon only allows to be used when a user has already logged in.

Such a confusing advise. Why would you need to use an external PHP script if you can add your code to event like BeforeProcess of Register or Login page?

A
acpan 7/7/2021

Please disregard my advice earlier, you can simply use DB API in before login process event, as what admin mentioned and using Fernando's suggestion. I was quoting one of my projects where i needed access to the database before user logs in, in a more complex situation, it is not necessary in your case.

Here's what you can do:

Login Before Process event:

$rs = DB::Query("select count(*) as count from user_table");
while( $data = $rs->fetchAssoc() ) {
$user_count= $data["count"];
}
// Uncomment below to check:
// echo "User Count=".$user_count; exit;
$pageObject->setProxyValue("user_count", $user_count);

Login Javascript On Load event (as Fernando's advice):

if ( proxy["user_count"] > 100) {
$('[data-itemid="loginform_register_link"]').hide();
}