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: HELP me please

  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HELP me please

    i am currently makeing a webpage and i have this displaied

    <table width="100%" border="0">
    <tr>
    <td><div align="center"><font size="2"><strong><?php echo date("l, d-M-Y H:i:s T"); ?></strong></font></div></td>
    <td><div align="center"><font size="2"><strong><?php echo "$REMOTE_ADDR"; ?></strong></font></div></td>
    <td><div align="center"><font size="2"><strong><?php echo "$HTTP_USER_AGENT"; ?></strong></font></div></td>
    </tr>
    </table>

    it shows the time ip and agent is there anyway to save that to a txt file like when some 1 goes to my page to save that "the results" to a txt file

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Are you wanting to create something like a log file of that information for each person that visits the page? And end up with a text file something like?

    time, ip, agent
    time, ip, agent
    time, ip, agent
    time, ip, agent
    time, ip, agent
    time, ip, agent
    time, ip, agent
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes but i cannot have a MySQL db because my host ipowerweb is bein a gerk so i have to have it in a .txt file for now

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,273
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You don't have to have a db for this. If you are getting many visitors though this log file will grow very quickly and writing to a file can become much slower than using a db. Here is a simple script I threw together:

    PHP Code:
    <?php 
    $file_name 
    "accesslog.txt"
    $data date("l, d-M-Y H:i:s T").",".$REMOTE_ADDR.",".$HTTP_USER_AGENT."\n";

    $file_pointer fopen($file_name"a"); 
    $lock flock($file_pointerLOCK_EX); 

    if (
    $lock){
     
    fputs($file_pointer$data); 
     
    flock($file_pointerLOCK_UN); 

    fclose($file_pointer); 
    ?>
    Enjoy
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    gerk - splendid terminology says so much

    side notes: You'll need chmod permissions set for the folder with
    the text file in it - if you get a 'permission denied' you'd need to
    change the chmod.

    To get the values back out in a nice table

    echo '<table width="100%" border="0">';
    $iplist = fopen('accesslog.txt');
    if(file_exists($iplist)) {
    $fp = fopen($iplist,"r");
    while($tdata = fgetcsv ($fp, 1000, ",")) {
    echo '<tr>
    <td><div align="center"><font size="2"><strong>'.$tdata[0].'</strong></font></div></td>

    <td><div align="center"><font size="2"><strong>'.$tdata[1].'</strong></font></div></td>

    <td><div align="center"><font size="2"><strong>'.$tdata[2].'</strong></font></div></td>

    </tr>';
    }
    fclose ($fp);
    echo '</table>';
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    without the dodgy linebreaks - no prizes for guessing who forgot
    the ol' [ php] and [ /php] surrounds.

    As spooks says - that file can get real large real quick so be
    careful.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

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