Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Stats Tracking With Image

    I am trying to track page load using an image. So basically I put the code <img src="image.php"> I want the code in image.php to insert into a database what page the code <img src="image.php"> is in.

    PHP Code:
    $_SERVER["REQUEST_URI"]; 
    Does not work as it shows image.php. How do I get the page URL? Any help would be great. Thanks.
    Last edited by pixencom; 05-15-2008 at 01:04 AM.
    Atlanta Web Design <- They do good work.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Have you tried the $_SERVER['HTTP_REFERER']? That may be the one your looking for.
    I don't recommend actually tracking this, as it will be hell on your database. Instead, if its a hotlinking issue, I'd just deny anyone who is outside of my site to link the image. Of course, they can always just save your image, but at least they are not using your bandwidth anymore.

    Oh, I should mention as well, this is not an overly reliable method, referer (yes it is spelled wrong I don't know why they did that >.<) can be changed by client. But at least it will dissuade most users
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Its not for hotlinking. I want to track how many users come on a particular page. So in the database I have an entry for each page. When a user visits a page, another hit gets added to the entry corresponding to the page.
    Atlanta Web Design <- They do good work.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yep, ok then that should do it as long as the referer is being sent along. I may suggest that you use some php logic to first determine if a record exists for a specific site (or page if you really wanted it, but I'd just do the site), and a counter variable that you can increment. Use a long for this.

    Good luck mate!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New Coder
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Referrer is the only way it will work?
    Atlanta Web Design <- They do good work.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Hmm, best I can think of off the top of my head in PHP anyway. I'll look around as well to see if I can find a better solution, but I've never actually done a tracker between multiple locations before - only the hotlink prevention.

    There is probably a more advanced solution (curl or something of the sorts), but I'm not sure how it would be put together. Perhaps someone else on the site has already built a similar service before, and could let you know of another way.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    New Coder
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts
    http://www.statcounter.com/ is implementing exactly what I would like to code. If anyone is confused at what I want, visit their site.
    Atlanta Web Design <- They do good work.

  • #8
    Regular Coder logictrap's Avatar
    Join Date
    Apr 2008
    Posts
    155
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Here's one method that should work - this assumes your page is a php file:

    1) Set up a MYSQL database with at least two fields: (id & page name) make id an auto increment field and page name a varchar(255).
    2) Create a variable on each page to store it's page name (ie $page='photos.php'.
    3) Use php to insert the page name ($page) into the database on each visit.
    4) To view the page count use a mysql statement to return the count for each page name.

    Which came first - the chicken or the egg? The egg... [ticket closed]
    If a tree falls... does it make a sound? Yes.............. [ticket closed]

  • #9
    New Coder
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by logictrap View Post
    Here's one method that should work - this assumes your page is a php file:

    1) Set up a MYSQL database with at least two fields: (id & page name) make id an auto increment field and page name a varchar(255).
    2) Create a variable on each page to store it's page name (ie $page='photos.php'.
    3) Use php to insert the page name ($page) into the database on each visit.
    4) To view the page count use a mysql statement to return the count for each page name.
    Thank you for your reply. This is what I have now:

    1) I have the DB setup
    2) On every page I have included a PHP file
    3) The PHP file updates the information to the Database

    What I want is instead of including this PHP file, I want it to be an image that I can put into <img src="log.php">. When I do that, I loose the page information. Right now I am getting the page with REQUEST_URI, but that doesnt work when log.php is called upon as an image.
    Atlanta Web Design <- They do good work.

  • #10
    New Coder
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    6
    Thanked 0 Times in 0 Posts
    UPDATE:

    Just wanted to confirm that HTTP_REFERER gets the job done but that wont work for people with sending referrer info off. Any ideas?
    Atlanta Web Design <- They do good work.

  • #11
    Regular Coder logictrap's Avatar
    Join Date
    Apr 2008
    Posts
    155
    Thanks
    11
    Thanked 3 Times in 3 Posts
    you might be loosing the referrer value because you are calling the log.php from another page - so the referrer is the page calling log.php not the original referrer.

    Try using a session value to store the referrer value and the use the session value in the log.php to retrieve it.

    Main Page:
    Code:
    <?php
    session_start();
    $_SESSION['referrer']=$_SERVER['HTTP_REFERER'];
    ?>
    log.php
    Code:
    <?php
    session_start();
    // MySQL insert statement - insert $_SESSION['referrer'] into some table
    ?>
    Last edited by logictrap; 05-15-2008 at 02:39 PM. Reason: fix code

    Which came first - the chicken or the egg? The egg... [ticket closed]
    If a tree falls... does it make a sound? Yes.............. [ticket closed]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •