What is a secure way or best practice to disable an html link or button based on php conditions?

Originally, the link <a> in a PHP HTML file is clickable. Now I need to add PHP "if-else" to make <a> is not clickable based on some condition. How can I achieve this in a secure way?

<? if (condition) : ?> 
   <a> is clickable (
       by using this.container.on('click', '.class-point-to-a-link', function (e) {
<? else: ?>
   probably using <span> or disable the link using css?
<? endif; ?>

I have several thoughts but not sure what is the best practice or how you guys would do it.

  1. in the else branch, I will not use the <a> tag, instead, I will use a <span> or some other tag, so the javascript on("click"…) will not find the span and will not trigger the action at all.
    But I have a security concern that someone may inspect and change the span to <a>, then the link will work.

  2. add some CSS to the <a> to make it not clickable? I have the same security concern.

  3. inside the on("click"…) part, I will add the condition one more time based on the data from the backend. This is the best method that I can think of, but is there a better way to not apply the "if-else condition" twice?

This is a question with several small questions.

Source: CSS – Stack Overflow

November 5, 2021
Category : News
Tags: conditional-statements | css | html | javascript | php

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.