[PHP] Log who visits your Petpage

Discussion in 'Code Snippets and Tutorials' started by Belaarx, Sep 23, 2008.

Thread Status:
Not open for further replies.
  1. Belaarx

    Belaarx Level I

    Joined:
    Sep 23, 2008
    Messages:
    135
    Likes Received:
    16
    Location:
    San Diego
    Hey everyone, I am a new member here and I was playing around with some ideas this morning and I figured out how you can log the username for anyone who visits your petpage. This may be considered "useless" but you can possibly use this to check who read your "Avatar Lending Requirement" page, or just use it to generate a list of usernames. Anyways, here how to do it:

    • REQUIREMENTS:
    • Access to Web Server that supports PHP (Google for a free one)
    • A Neopets account over 24 hours old.
    • A Neopet

    STEPS:
    1. Create a new FOLDER somewhere on your server called "helloworld.jpg" (Name of the FOLDER. No quotes.).

    2. Create an empty Text file called "log.txt", and upload inside of the folder you just made. ("helloworld.jpg").

    3. Make a new PHP FILE named "index.php" (Once again, no quotes.)

    4. Inside of the file, put the following code in:
    Code (Text):
    1. <?php
    2.  
    3. $val = $_GET['username'];  
    4.  
    5. $data = $val."\n";
    6.  
    7. $fp = fopen("log.txt", "a");
    8.  
    9. fwrite($fp, $data);
    10.  
    11. fclose($fp);
    12.  
    13. ?>
    5. Upload "index.php" to your folder "helloworld.jpg"

    6. Now, on your petpage, put the following line of code in (Change "YOURWEBSITEHERE" to your website!)
    Code (Text):
    1. <img src="http://YOURWEBSITEHERE.com/helloworld.jpg?username=#VISITOR">
    7. Make sure that you have updated your petpage with that code, and now test it by going to your petpage.

    8. You will be able to check the log of the usernames at:
    That is it! I will add a list of free PHP hosts at the end of the page if you guys find any that have worked for you.
     
    expon and Cacklenub like this.
  2. Asphodan

    Asphodan Level III

    Joined:
    Apr 19, 2008
    Messages:
    377
    Likes Received:
    5
    I don't see the usefulness here, but I do like the simple coolness it has. Keep up this behaviour and you'll be one very welcome person on this forum. :)
     
  3. Zer0

    Zer0 Level IV

    Joined:
    Mar 2, 2008
    Messages:
    3,037
    Likes Received:
    180
    Location:
    Home sweet home
    Haha, nice code snippet ;)
    With certain web hosts, they will allow you to have file extensions other than *.php to execute PHP scripts. Thus you could put the script in a text file called "helloworld.jpg" and it work work similarly. Just a slightly simpler thought for people who may have access to such a host. :)

    And welcome to Neofriends :)
     
  4. Cacklenub

    Cacklenub Level IV

    Joined:
    May 10, 2008
    Messages:
    1,345
    Likes Received:
    58
    Can anyone recommend a site for this?? (easy to use for a nub like me haha)
     
  5. ricky92

    ricky92 Administrator
    Staff Member

    Joined:
    Nov 10, 2006
    Messages:
    1,866
    Likes Received:
    67
    You can use freehostia, it's really simple to register an account and put a site on it.
    However, you can also use the Apache mod_rewrite Module, it would be alot cleaner to do. You can use the rewriterule
    Code (Text):
    1. RewriteRule /image\.jpg /script.php
    This would rewrite the url "http://www.yoursite.com/image.jpg" to "http://www.yoursite.com/script.php" with no redirection.
     
  6. Zach

    Zach Newbie

    Joined:
    May 26, 2008
    Messages:
    31
    Likes Received:
    1
    Welcome to NeoFriends!

    Just a pointer:

    In PHP, using '' instead of "" is faster...

    Can't find proof right now, will later :)

    Also,

    Is there a reason that quick reply doesn't work with Google Chrome?
     
  7. Zach

    Zach Newbie

    Joined:
    May 26, 2008
    Messages:
    31
    Likes Received:
    1
    I really want to post this on my shop. I am using FreeHostia :)
     
  8. neohacker

    neohacker Level I

    Joined:
    Jan 1, 2009
    Messages:
    54
    Likes Received:
    1
    You do realize that this can be a tutorial for a cookie grabber.
     
  9. Smirnoff

    Smirnoff Level IV

    Joined:
    Jan 15, 2007
    Messages:
    869
    Likes Received:
    14
    Do they still even work on neopets?

    Regarding this: I think TNT would have a filter running to monitor if a petpage is sending out packets when a user visits. Though I can't base this on anything more then common sense.
     
  10. Zer0

    Zer0 Level IV

    Joined:
    Mar 2, 2008
    Messages:
    3,037
    Likes Received:
    180
    Location:
    Home sweet home
    No, this is not a tutorial for CGers. CGers require access to document.cookie, which I'm pretty sure is blocked on Neopets (directly anyways)
    TNT can't monitor the "packets" of data since the "image" is directly loaded from the hosting server to the browser. They can only monitor the code that you put on the petpage.
     
  11. Smirnoff

    Smirnoff Level IV

    Joined:
    Jan 15, 2007
    Messages:
    869
    Likes Received:
    14
    Ahh, I see now. I wasn't really paying attention lol.
     
  12. Niacin

    Niacin Level II

    Joined:
    Apr 15, 2009
    Messages:
    273
    Likes Received:
    13
    Location:
    At some random American University
    I don't me dig this post up so please don't flame me for doing so just trying to help:


    If you want a pre-made one with absolutely no work go to NeoMallers (the website) and you can make these for petpages by simply typing in your pets name :D
     
Thread Status:
Not open for further replies.