Hello, This is the situation: (the tracking mentioned below needs to be done via PHP so I am posting in this forum) I have this code: <script type="text/javascript"> document.write("<img src=\'http://localhost/log.php?q=js\'>"); </script> <noscript> <img src=\'http://localhost/log.php?q=NON\'> </noscript> Code (markup): The above code is on a html page. Now when the page loads in browser, the "?q=js" gets triggerred if browser has java enabled. If it does not, the "?q=NON" gets triggered, and my php script is able to successfully render the image. (it's actually a web hits tracking php script. The image shows the total number of hits to the page.) Now here is the problem. When a bot visits the page to index it, and because there is no browser there, so none of the above 2 are triggered, and the php script fails to track the hit completely. How do I send a request to the image URL if the bot visits the page? Please note that php code cannot be added to the html page, and javascript does not work with bots (no browser at all). So the noscript is also not working. Please suggest what to do. Thanks
Have you thought about simply include the <img> tag in the html source code and not in js or noscript?
<?php $bots = array('google', 'alexa'); if (preg_match('#(?:'.implode('|', preg_quote($bots)).')#i', $_SERVER['HTTP_USER_AGENT'])): //do something... else: ?> <script type="text/javascript"> document.write("<img src='http://localhost/log.php?q=js'>"); </script> <noscript><img src="http://localhost/log.php?q=NON"></noscript> <?php endif; ?> PHP: