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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post

    Need help with user logger, getting a parse error

    Hey,

    Im trying to get back into php lately because ive fallen in love with it again and came across an old script that I and a friend had made that was used as one of those Ip telling signature pictures that everyone had a while back. Anyways since it was written to cut the excess jargin out of the client info etc and just give plain results that anyone could understand, like Operationg system = windows xp, I figured itd be a good piece to a user information logging system, I modified it so that 'its supposed' to write the info into a text file in the same directory but when its ran it gives me this error,

    Parse error: parse error, unexpected T_VARIABLE in c:\phpdev5\www\logs\logwriter.php on line 99
    Here is the entire code for the scipt incase it may have something to do with something above the line specified.

    PHP Code:
    <?php
    //browser type 
       
    $agent $HTTP_USER_AGENT;
       if ( 
    strstr($agent"MSIE 5") ) $browser "using IE 5";
       elseif ( 
    strstr($agent"MSIE 6") ) $browser "using IE 6";
       elseif ( 
    strstr($agent"MSIE 4") ) $browser "using IE 4";
       elseif ( 
    strstr($agent"Firebird") ) $browser "using Firebird";
       elseif ( 
    strstr($agent"Safari") ) $browser "using Safari";
       elseif ( 
    strstr($agent"Mozilla/5") ) $browser "using Mozilla/Netscape 5";
       elseif ( 
    strstr($agent"Mozilla/6") ) $browser "using Netscape 6";
       elseif ( 
    strstr($agent"Mozilla/4") ) $browser "using Netscape 4";
       elseif ( 
    strstr($agent"Opera") ) $browser "using Opera";
       else 
    $browser "";


    // get IP and resolve IP
    $ip $REMOTE_ADDR;
    $resolved gethostbyaddr ($REMOTE_ADDR);



    // check for non resolve of IP and rip domain if resolved
    if ($resolved == $ip) {
    $isp ".. Can't Resolve IP";
    }
    else
    {
    $str preg_split("/\./"$resolved);
    $i count($str);
    $x $i 1;
    $n $i 2;
    $isp $str[$n] . "." $str[$x];
    }

    // Simple OS Detection

    $os $HTTP_USER_AGENT;
    $oslist = Array (

    // Windows
    "Win|Windows",
    "Win16|Windows",
    "Win95|Windows 95",
    "Win98|Windows 98"
    "WinME|Windows ME"
    "Win32|Windows",
    "WinNT|Windows NT",
    "Windows 3.1|Windows 3.1",
    "Windows 95|Windows 95",
    "Windows CE|Windows CE",
    "Windows 98|Windows 98",
    "Windows ME|Windows ME",
    "Windows NT|Windows NT",
    "Windows NT 5.0|Windows 2000",
    "Windows NT 5.1|Windows XP",

    // Macintosh
    "Mac_68000|MacOS m68K",
    "Mac_68K|MacOS m68K",
    "Mac_PowerPC|MacOS PPC",
    "Mac_PPC|MacOS PPC",
    "Macintosh|MacOS",

    // Unices
    "X11|UNIX",
    "BSD|BSD",
    "SunOS|SunOS",
    "IRIX|IRIX",
    "HP-UX|HP-UX",
    "AIX|AIX",
    "QNX|QNX",
    "SCO_SV|SCO UNIX",
    "FreeBSD|FreeBSD",
    "NetBSD|NetBSD",

    // Linux 
    "Linux|Linux",
    "Debian|Debian GNU/Linux",

    // Other 
    "BeOS|BeOS",
    "OS/2|OS/2",
    "AmigaOS|AmigaOS",

    );

    foreach (
    $oslist as $osnow) {
    $osnow explode ("|"$osnow);
    if (
    eregi ($osnow[0], $os)) {
    $endos $osnow[1];
    $check "No";
    } elseif (
    $check != "No") {
    $endos "Unknown";
    }
    }

    // Opens the log file for writing and writes
    $start "-------------------------------------------------------------------------------------------";
    $content1 "Visitors Ip - " $ip;
    $content2 "Visitors ISP - " $isp;
    $content3 "Visitors Operating System - " $os;
    $content4 "Visitors Browser - " $browser;
    $end "-------------------------------------------------------------------------------------------";


    $fp fopen("log.txt","a");
    fwrite($fp,"$start content1 $content2 $content3 $content4 $end");
    fclose($fp);
    ?>
    Line 99 is the line at the botton that starts with the $content1 variable, im a bit rusty on my php but I thought that the unexpected T_variable was caused by an important character or something missing from the script but I didnt leave anything out?

    Hopefully its not too much trouble and It will start working, this could be pretty useful for me and maybe other people even though its a bit dated ( no detection for firefox ), from here im trying to learn how to get this stuff put into a mysql database, but thatll be for another day.

    Thanks to those who reply in advance cuz im low on sleep and wont be able to reply for about 12 hours, as ill be sleeping.
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #2
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $content1 "Visitors Ip - " $ip;
    $content2 "Visitors ISP - " $isp;
    $content3 "Visitors Operating System - " $os;
    $content4 "Visitors Browser - " $browser
    You forgot to connect the string and the variable together. An easy error to make while sleepy.
    "$question = ( to() ) ? be() : ~be();"

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    Thanks lol at least it wasnt something major, it works in the sense that it doesnt give me a parse error anoymore but now it isnt putting the operating system info into the log file, only the part where it says 'Visitors Operating System' goes in.....odd.
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #4
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Shouldn't you be writing $endos instead of $os?
    "$question = ( to() ) ? be() : ~be();"

  • #5
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    Thats what I thought too but its been so long since ive messed with this script Ive forgotten how alot of the things worked, I only have a pre-final release of my script available because I forgot to backup the final working one, It was a miracle/mistake that I even came across this old one. Im pretty sure tho now that it is supposed to be $os because that was what was in the section that was to be printed to the image file.

    Here is the current log that is being written

    --------------------------------------------------------------------------------------------
    Visitors Ip -
    Visitors ISP - .BYRAN
    Visitors Operating System - Unknown
    Visitors Browser -
    Visitor Came From -
    Visitor Visited On - Sunday 24th of April 2005 12:36:02 PM
    --------------------------------------------------------------------------------------------
    And here is the most up-to-date php script, this is kinda wierd that it isnt working, lol its showing my windows screen name as my isp...thats not right but perhaps that is because its running locally, who knows.

    PHP Code:
    <?php
    //browser type 
       
    $agent $HTTP_USER_AGENT;
       if ( 
    strstr($agent"MSIE 5") ) $browser "using IE 5";
       elseif ( 
    strstr($agent"MSIE 6") ) $browser "using IE 6";
       elseif ( 
    strstr($agent"MSIE 4") ) $browser "using IE 4";
       elseif ( 
    strstr($agent"Firebird") ) $browser "using Firebird";
       elseif ( 
    strstr($agent"Safari") ) $browser "using Safari";
       elseif ( 
    strstr($agent"Mozilla/5") ) $browser "using Mozilla/Netscape 5";
       elseif ( 
    strstr($agent"Mozilla/6") ) $browser "using Netscape 6";
       elseif ( 
    strstr($agent"Mozilla/4") ) $browser "using Netscape 4";
       elseif ( 
    strstr($agent"Opera") ) $browser "using Opera";
       else 
    $browser "";


    // get IP and resolve IP
    $ip $REMOTE_ADDR;
    $resolved gethostbyaddr ($REMOTE_ADDR);



    // check for non resolve of IP and rip domain if resolved
    if ($resolved == $ip) {
    $isp ".. Can't Resolve IP";
    }
    else
    {
    $str preg_split("/\./"$resolved);
    $i count($str);
    $x $i 1;
    $n $i 2;
    $isp $str[$n] . "." $str[$x];
    }

    // Simple OS Detection

    $os $HTTP_USER_AGENT;
    $oslist = Array (

    // Windows
    "Win|Windows",
    "Win16|Windows",
    "Win95|Windows 95",
    "Win98|Windows 98"
    "WinME|Windows ME"
    "Win32|Windows",
    "WinNT|Windows NT",
    "Windows 3.1|Windows 3.1",
    "Windows 95|Windows 95",
    "Windows CE|Windows CE",
    "Windows 98|Windows 98",
    "Windows ME|Windows ME",
    "Windows NT|Windows NT",
    "Windows NT 5.0|Windows 2000",
    "Windows NT 5.1|Windows XP",

    // Macintosh
    "Mac_68000|MacOS m68K",
    "Mac_68K|MacOS m68K",
    "Mac_PowerPC|MacOS PPC",
    "Mac_PPC|MacOS PPC",
    "Macintosh|MacOS",

    // Unices
    "X11|UNIX",
    "BSD|BSD",
    "SunOS|SunOS",
    "IRIX|IRIX",
    "HP-UX|HP-UX",
    "AIX|AIX",
    "QNX|QNX",
    "SCO_SV|SCO UNIX",
    "FreeBSD|FreeBSD",
    "NetBSD|NetBSD",

    // Linux 
    "Linux|Linux",
    "Debian|Debian GNU/Linux",

    // Other 
    "BeOS|BeOS",
    "OS/2|OS/2",
    "AmigaOS|AmigaOS",

    );

    foreach (
    $oslist as $osnow) {
    $osnow explode ("|"$osnow);
    if (
    eregi ($osnow[0], $os)) {
    $endos $osnow[1];
    $check "No";
    } elseif (
    $check != "No") {
    $endos "Unknown";
    }
    }

    // Logs where the user came from
    $trace $HTTP_REFERRER;

    // Logs when the user visited
    $when date("l dS of F Y h:i:s A");

    // Opens the log file for writing and writes
    $start "--------------------------------------------------------------------------------------------";
    $content1 "Visitors Ip - " $ip;
    $content2 "Visitors ISP - " .  $isp;
    $content3 "Visitors Operating System - " $os;
    $content4 "Visitors Browser - " $browser;
    $content5 "Visitor Came From - " $trace;
    $content6 "Visitor Visited On - " $when;
    $end "--------------------------------------------------------------------------------------------";


    $fp fopen("log.txt","a");
    fwrite($fp,"$start\n$content1\n$content2\n$content3\n$content4\n$content5\n$content6\n$end");
    fclose($fp);
    ?>
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #6
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One part:

    $HTTP_REFERRER;
    should be
    getenv("HTTP_REFERRER");

    For that matter, they all should be.
    "$question = ( to() ) ? be() : ~be();"

  • #7
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    Even with that changed it still doesnt enter anything into the logs. Im gonna put it online and see if it has any effect on the working of the script.
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #8
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh oops, you don't want getenv, this is what you want:

    $_SERVER['HTTP_REFERER'];

    and so on. Sorry, I'm a bit tired.
    "$question = ( to() ) ? be() : ~be();"

  • #9
    Regular Coder
    Join Date
    Sep 2002
    Location
    California
    Posts
    511
    Thanks
    1
    Thanked 1 Time in 1 Post
    I was gonna say that didnt look familiar, anyways I went thru the whole script and changed all the stuff to $_server['bleh'] and now quite a bit of stuff has started working, for the most part, the operating system detection is malfunctioning so Ill stare really hard at it and hope it works 5 minutes from now =) and then the referrer still doesnt work.

    Here is the New Log
    --------------------------------------------------------------------------------------------
    Visitors Ip - 127.0.0.1
    Visitors ISP - .localhost
    Visitors Operating System - Windows XP
    Visitors Browser - Mozilla/Netscape 5
    Visitor Came From -
    Visitor Visited On - Sunday 24th of April 2005 04:40:03 PM
    --------------------------------------------------------------------------------------------
    And here is the revised code:

    PHP Code:
    <?php
    //browser type 
       
    $agent $_SERVER['HTTP_USER_AGENT'];
       if ( 
    strstr($agent"MSIE 5") ) $browser "Internet Explorer 5";
       elseif ( 
    strstr($agent"MSIE 6") ) $browser "Internet Explorer 6";
       elseif ( 
    strstr($agent"MSIE 4") ) $browser "Internet Explorer 4";
       elseif ( 
    strstr($agent"Firebird") ) $browser "Firebird";
       elseif ( 
    strstr($agent"Safari") ) $browser "Safari";
       elseif ( 
    strstr($agent"Mozilla/5") ) $browser "Mozilla/Netscape 5";
       elseif ( 
    strstr($agent"Mozilla/6") ) $browser "Netscape 6";
       elseif ( 
    strstr($agent"Mozilla/4") ) $browser "Netscape 4";
       elseif ( 
    strstr($agent"Opera") ) $browser "Opera";
       else 
    $browser "";


    // get IP and resolve IP
    $ip $_SERVER['REMOTE_ADDR'];
    $resolved gethostbyaddr ($_SERVER['REMOTE_ADDR']);



    // check for non resolve of IP and rip domain if resolved
    if ($resolved == $ip) {
    $isp ".. Can't Resolve IP";
    }
    else
    {
    $str preg_split("/\./"$resolved);
    $i count($str);
    $x $i 1;
    $n $i 2;
    $isp $str[$n] . "." $str[$x];
    }

    // Simple OS Detection

    $os $_SERVER['HTTP_USER_AGENT'];
    $oslist = Array (

    // Windows
    "Win|Windows",
    "Win16|Windows",
    "Win95|Windows 95",
    "Win98|Windows 98"
    "WinME|Windows ME"
    "Win32|Windows",
    "WinNT|Windows NT",
    "Windows 3.1|Windows 3.1",
    "Windows 95|Windows 95",
    "Windows CE|Windows CE",
    "Windows 98|Windows 98",
    "Windows ME|Windows ME",
    "Windows NT|Windows NT",
    "Windows NT 5.0|Windows 2000",
    "Windows NT 5.1|Windows XP",

    // Macintosh
    "Mac_68000|MacOS m68K",
    "Mac_68K|MacOS m68K",
    "Mac_PowerPC|MacOS PPC",
    "Mac_PPC|MacOS PPC",
    "Macintosh|MacOS",

    // Unices
    "X11|UNIX",
    "BSD|BSD",
    "SunOS|SunOS",
    "IRIX|IRIX",
    "HP-UX|HP-UX",
    "AIX|AIX",
    "QNX|QNX",
    "SCO_SV|SCO UNIX",
    "FreeBSD|FreeBSD",
    "NetBSD|NetBSD",

    // Linux 
    "Linux|Linux",
    "Debian|Debian GNU/Linux",

    // Other 
    "BeOS|BeOS",
    "OS/2|OS/2",
    "AmigaOS|AmigaOS",

    );

    foreach (
    $oslist as $osnow) {
    $osnow explode ("|"$osnow);
    if (
    eregi ($osnow[0], $os)) {
    $endos $osnow[1];
    $check "No";
    } elseif (
    $check != "No") {
    $endos "Unknown";
    }
    }

    // Logs where the user came from
    $trace $_SERVER['HTTP_REFERER'];

    // Logs when the user visited
    $when date("l dS of F Y h:i:s A");

    // Opens the log file for writing and writes
    $start "--------------------------------------------------------------------------------------------";
    $content1 "Visitors Ip - " $ip;
    $content2 "Visitors ISP - " .  $isp;
    $content3 "Visitors Operating System - " $endos;
    $content4 "Visitors Browser - " $browser;
    $content5 "Visitor Came From - " $trace;
    $content6 "Visitor Visited On - " $when;
    $end "--------------------------------------------------------------------------------------------";


    $fp fopen("log.txt","a");
    fwrite($fp,"$start\n$content1\n$content2\n$content3\n$content4\n$content5\n$content6\n$end");
    fclose($fp);
    ?>
    Ive yet to test it online, my site is down atm so I cant test it in a 'real environmet'

    Thank you for your help so far, I appreciate it.

    EDIT: You were right, it should have been the $endos variable, I had it all wrong from the start, now to work on the referrer and then try and update the browser detection.
    Last edited by Bry Man; 04-25-2005 at 12:42 AM.
    When traveling down the road of life, Try not to drag your face in the gravel.


  •  

    Posting Permissions

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