Suggest on HTML and BOT issue please.

Discussion in 'PHP' started by JEET, Sep 7, 2010.

  1. #1
    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
     
    JEET, Sep 7, 2010 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    Have you thought about simply include the <img> tag in the html source code and not in js or noscript?
     
    stephan2307, Sep 7, 2010 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Yes, but still won't work because there is no browser, so the html is not at all processed.
    Thanks :)
     
    JEET, Sep 7, 2010 IP
  4. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #4
    OK I see. Why can't you use any PHP?
     
    stephan2307, Sep 7, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    <?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:
     
    danx10, Sep 7, 2010 IP