How to know when a link is clicked in php
I want to 开发者_如何学JAVAknow when a link is clicked with php. Can anyone tell me how to do that?
You can't. PHP is a preprocessor on the server side and doesn't know anything about what happens on the client side (the browser).
What you can do is create either an AJAX request that will call a PHP script on your server whenever the user clicks the link, or point the link at a PHP script directly.
Because the browser will make a request to the URL the link refers to. Simply put a PHP script at that URL and you can detect the click there.
You can add onclick event like this:
<a href="http://www.yourUrl.com" onclick="doSomething();" >text</a>
<script>
function doSomething()
{
......
}
</script>
if you just want to record the fact the link was clicked
<a href="/link_count.php?link=www.google.com">LINK</a>
in link_count.php record the click and send them to the link with header location.
精彩评论