0

Is there any method to determine whether the user clicked somewhere on the page on PHP? I want to fire a pixel when a user clicked somewhere on the page.

Thanks for your time

nethsrk
  • 78
  • 8
  • No, not with PHP. PHP runs before the page is sent to the browser, so by the time the user sees the page, PHP is done. However, javascript can do this. – aynber Sep 07 '22 at 19:57

3 Answers3

1

The web page showed in the browser and php are separated world.

Yes php on the server generate the webpage which then is sent to the browser which "execute" it.

If you want to track where user click, you should use some javascript which send the x,y to the server via ajax

To get x,y on mouse click you an use the js in this answer

javascript get x and y coordinates on mouse click

But instead of printing it just send them to the server via javasccript.

Roberto Braga
  • 569
  • 3
  • 8
0

PHP is a server-side scripting language. PHP doesn't handle events like mouse or keyboard clicks. For your needs, you should use JavaScript (if your application is meant to work in a browser later on) JavaScript is a client-side scripting language.

Steffen
  • 501
  • 1
  • 14
0

To "fire a pixel" when a user clicks somewhere within the page sounds like a task that could easily be done by using JavaScript (JS). You can implement this JS code within the <script>-Tag anywhere within the HTML part of a PHP script.

See

gretarsson
  • 31
  • 1
  • 7