Home > other >  PHP Check whether user clicked on the page
PHP Check whether user clicked on the page

Time:09-08

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

CodePudding user response:

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.

CodePudding user response:

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.

CodePudding user response:

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

  •  Tags:  
  • php
  • Related