Q:

How to prevent button from being clicked more than 1 in a lifetime

I have a button where logged in users can click and download some material. I want this button to be clicked only once in a lifetime and then either disappear or be disabled. So once the user clicks the button they download their stuff and then the button is no longer active. What is the best way to do this?
<button type="submit" class="button">Get Certificate</button>

A:

Well am assuming what you meant by once in a lifetime is, even after the user logout and login again, they still won't be able to re-download the file. In that case as mentioned by @saifiqbal, you have to save the state on a database. Create a table named user_certificate for example, add a user_id reference column and a Boolean type column named downloaded. You can then populate this table when user successfully download their certificate by setting downloaded to true for the user. Then on your download page check if downloaded=true to disable the button.
<button type="submit" class="button" <?php if ($downloaded==true) echo "disabled; ?> >Get Certificate</button>

The variable $downloaded is fetched from the database. You can choose to name the database table, columns and the variable anything you want, just giving you an idea.
Pardon me for any typo, I typed this from my cellphone.

