Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9246709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:33:18+00:00 2026-06-18T09:33:18+00:00

In PHP, I want to save messages to a text file and read the

  • 0

In PHP, I want to save messages to a text file and read the log file using php.

Here is what I have so far:

function LogUserActivity($LogFile, $Activity){
    $UserIp = $_SERVER['REMOTE_ADDR'];
    $TimeRef = date('d-m-Y H:i T');

    $Handle = fopen($LogFile, 'a');
    $Data = $UserIp.'|'.$TimeRef.'|'.$Activity.'~';
    fwrite($Handle, $Data);
    fclose($Handle);
}

function ReadUserActivity($LogFile){
    global $log;
    $LogFile = file_get_contents($LogFile);
    $ExplodedLogFile = explode("~", $LogFile);
    $ArrayNum = count($ExplodedLogFile);

    $i = 0;
    while ( $i <= $ArrayNum ){
        $log[$i] = explode("|", $ExplodedLogFile[$i]);
        $i++;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:33:19+00:00Added an answer on June 18, 2026 at 9:33 am

    Call LogUserActivity at the beginning of every script, passing it the file you want to write to and some message to yourself. E.g.:

    <?php
    include('the-file-where-you-put-these-functions.php');
    LogUserActivity('/tmp/example.log', 'Porkchop sandwitches!');
    // the rest of your script
    ?>
    

    Call the other function in the script you’re gonna use to inspect the logs. It will set the $log variable which you can then print out however you want.

    Or just use this single liner:

    <?php
    file_put_contents("/tmp/stuff.txt", "penguins", FILE_APPEND); 
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to save an .XML file that i create with php dom, but
I have built a site using php and want to try keep it one
In my php application i want to create a error log in a text
I want to save XML files from a PHP script (original XML file and
i've made this php function to resize picture , and i want to save
I want to recognize (with php, mysql) and save which blog entries a user
I am using less php and want to implement an uncompiled version of the
I am working with php and want to have a page that has a
I have this string in php i want to skip the ppattern ------------------------------------------ FROM:Andy;
hi i have multidimensional array in php i want to remove an index from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.