Disabling hyperlink by using jquery and php

Hi,
The following piece of code is from DanSEO. Is any one can give me an example code using this code on an html page,as I am new to php and html programming. More over I want to show a hyperlink as disabled to users whome are not administrator. Is it is possible by using php coding(server side validation), if so please give a sample code.:slight_smile:

[QUOTE=DanSEO;3892743]

$(document).ready(function(){
$(“a”).click(function () {
$(this).fadeTo(“fast”, .5).removeAttr(“href”);
});
});

It would probably be easier to just use php without any javascript at all. Also if a person has javascript disabled then the link would show up regardless of whether they’re an admin or not.

In php you would just have


if($admin == true) echo '<a href="adminpage.php">Admin Page</a>';

Of course you would need to check the admin variable again on the admin page and if false then redirect to the main page.

PHP is a better solution than JavaScript for this problem because visitor can’t disable it.

If you want to block link execution on client side(jquery) you can try:


$('.admin_link_class').click(function(){
     return false; // prevents default action
});

The admin_link_class is class property of all links that you want to block.