检查是否<a> tag has been clicked with PHP

时间:2017-01-08 11:55:27

标签: php html

How can I check if an <a> tag in HTML is clicked in PHP?

I have tried it by if(isset[$_GET[ "idofLink"]), but in this case, I get the else statement.

File file1.php

<li class="active"><a name = "profile" href="includes/submit-profile.php">Profile</a></li>

File profile.php

if(isset("profile")){
  // Do something....
} else{
  // Do something else ...
}

1 个答案:

答案 0 :(得分:1)

您应该在链接中添加查询部分,例如... href="includes/submit-profile.php?submit_profile" ...,以便稍后您可以检查是否单击了链接。所以完整的<li>元素应该是这样的:

<li class="active"><a name = "profile" href="includes/submit-profile.php?submit_profile">Profile</a></li>

这就是你可以检查是否点击链接的方法:

if(isset($_GET['submit_profile'])){
    // do something
}else{
    // do something else
}