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 6 of 6

Thread: PHP ? thing

  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post PHP ? thing

    Ok, first off I'm a bit of a noob when it comes to PHP.

    What I am looking to do is find the IP address of my friend. I'm needing a code that when I send a specific link to my friend (example: http://example.com/index.php?specialcodetoidentify). I need it to write information to a file called ip-log.txt and it needs to have the time, date, IP and what URL the web page was viewed on.

    So when I send the link with a random .php?codeofmychoise, the ?endthing has to be in the ip-log.txt. Does anyone have a code that is able to do all this?

    Yes, I am a massive noob at PHP. Sorry!

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,471
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    IP addresses change ... as they are dynamic.
    Not reliable, and your friend may have a different one each time he/she accesses your site.

    Only an actual user login is accurate.

    Sorry, there's really no way to determine who the person is without a unique login.

  • #3
    New Coder
    Join Date
    Jan 2012
    Location
    RI, USA
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    $_POST['REMOTE_ADDR'] holds the viewer's IP address in PHP. However like mlseim said, IP addresses are easily changed.

    The PHP date object can get you the date when the page was accessed.

    date = date("n-j-Y"); will give you the date in the format of mm-dd-yyyy into a string.

    $_POST['HTTP_REFERER'] holds the page from where the user came from, but it cannot be really trusted because it is easily changeable.
    Last edited by Alternative; 01-11-2012 at 09:54 AM.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    No $_POST['REMOTE_ADDR'] doesn't hold the IP, nor does $_POST['HTTP_REFERER'] hold the referer. It should be $_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_REFERER'].
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Red_Rain (01-11-2012)

  • #5
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the current code I'm using:
    Code:
    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    $dt = date("l dS \of F Y h:i:s A");
    $file=fopen("ip_log.txt","a");
    $data = $ip.' '.$dt."\n";
    fwrite($file, $data);
    fclose($file);
    ?>
    All that gives me is the Time, Date, Month and the IP. How would I add
    Code:
    $_SERVER['HTTP_REFERER']
    to it though?

    Yes, I am just starting PHP.

  • #6
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    8
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CallumTennant View Post
    This is the current code I'm using:
    Code:
    <?php
    $ip = $_SERVER['REMOTE_ADDR'];
    $dt = date("l dS \of F Y h:i:s A");
    $file=fopen("ip_log.txt","a");
    $data = $ip.' '.$dt."\n";
    fwrite($file, $data);
    fclose($file);
    ?>
    All that gives me is the Time, Date, Month and the IP. How would I add
    Code:
    $_SERVER['HTTP_REFERER']
    to it though?

    Yes, I am just starting PHP.
    You were able to write all that above but not figure how to echo the referer?? LOL i am really new to PHP too so dont take my word for it but i think that you could just say

    PHP Code:
    $refer $_SERVER['HTTP_REFERER']
    ........ 
    $data $ip.' '.$dt."\n" $refer 

    Like i said, i do not KNOW but i think thats worth a shot. Good luck!


  •  

    Posting Permissions

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