This topic is locked

How to know when a link was clicked?

8/6/2021 2:40:54 PM
PHPRunner General questions
M
marcelorribas author

Hello,
I´ve created a snippet to recover from database an image and a hyperlink to display to the user as a clickable link.
So far so god, but I need to know when (if was clicked) the link is clicked to be able to insert a new record on the database.

My code:

$filesArray = my_json_decode($_SESSION["imganuncio"]);
if ($filesArray[0]['name']<>"")
{
echo "<a href='".$_SESSION["linkcpg"]."' target='_blank' rel='noopener noreferrer'><img src='".$filesArray[0]['name']."' class='anuncio'></a>";
}

Could someone give any ideas?
Thanks in advance,
Marcelo

admin 8/6/2021

To make it happen your links need to point to a special adidtional PHP file that would record something in the database and then redirect user to the actual link.

You can see an example of such a technique at https://stackoverflow.com/questions/37446443/php-tracking-mail-and-link-clicks

M
marcelorribas author 8/6/2021

Thanks Sergey.