Web Analytics Made Easy -
StatCounter HELP me please - CodingForum

Announcement

Collapse
No announcement yet.

HELP me please

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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
    CodingForum Supreme Overlord
    All Hail Spookster

    Comment


    • #3
      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

      Comment


      • #4
        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
        CodingForum Supreme Overlord
        All Hail Spookster

        Comment


        • #5
          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.

          Comment


          • #6
            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.

            Comment

            Working...
            X