Skip to content
  • Home
  • Server-Side
    • php
    • Node.js
    • ASP.NET
    • Magento
    • Codeigniter
    • Laravel
    • Yii
    • CRUD
      • CRUD Database Application
      • CRUD operation in Client side
      • CRUD operation with server side
  • JavaScript
    • AngularJS
    • Ajax
    • VueJs
    • jQuery
    • ReactJS
    • JavaScript
    • SEO
  • Programming
    • Android
    • C programming
    • CSS
    • Mysql
    • Mysqli
  • Technology
    • Software
      • webinar software
      • webinar conferencing software
      • soundproof
    • Adsense
      • Google
      • Earn Money
      • Google Adsense
        • Adsense fraud
        • Adsense Secrets
        • Adsense software
        • Adwords advice
        • Adwords strategy
        • Google adwords help
        • How to get google ads
    • Tips and Tricks
    • Interview
    • Insurance
    • Religious
    • Entertainment
      • Bollywood
      • tamilrockers
      • Hollywood
  • Health Care
    • LifeStyle
    • Women
    • Fashion
    • Top10
    • Jobs
  • Tools
    • Screen Resolution
    • WORD COUNTER
    • Online Text Case Converter
    • what is my screen resolution?
  • Guest Post
    • 4cgandhi
    • IFSC Code

How to create a logfile in PHP

August 20, 2019January 9, 2018 by Pakainfo

How to create a logfile in PHP

Today, We want to share with you How to create a logfile in PHP.
In this post we will show you how to php write to log file append, hear for Write a string to a file using PHP we will give you demo and example for implement.
In this post, we will learn about how to create a logfile in php? with an example.

How to create a logfile in PHP Example
How to create a logfile in PHP Example

Hear is simple Source code for create new Date wise log file using php

Creating write a log in php web/API or web – application is very easy.You simple just need to make a write logs error or success message single log.php file use it any place or any where in web-application all the error msg write do you need.

Read Also:  Access Tokens - Facebook Login - Facebook Open Graph API

$time_dt_log = date('Y-m-d h:i:sa');
$msg_log = "Your Are Most Welcome in live24u.com";
  
write_logs("**************###### Start Date Log For Day : '" . $time_dt_log . "'###**********");
write_logs($msg_log);
write_logs("**************##### END Date Log For Day : '" . $time_dt_log . "'###**********");
 
function write_logs($msg_log)
{
    $all_log_filesavename = "log";
    if (!file_exists($all_log_filesavename)) 
    {
        // make some directory/folder uploads.
        mkdir($all_log_filesavename, 0777, true);
    }
    $log_file_data = $all_log_filesavename.'/log_' . date('d-M-Y') . '.log';
    file_put_contents($log_file_data, $msg_log . "\n", FILE_APPEND);
}

Example 2 : Write a string to a file using PHP

How to creating log file in you web-application or PHP project in easy way
PHP Source code to log some any errors and Write warnings into a file in php

Read Also:  PHP - Paypal Payment Gateway Integration

//define PHP function name  
function live_log($arraymsg)  
{  
	//define empty string                                 
	$stmntEntry="";  
	
	//get the Data event occur PHP date time,when it will happened  
	$Data_arLog['event_datetime']='['.date('D Y-m-d h:i:s A').'] [client '.$_SERVER['REMOTE_ADDR'].']';  
	
	//if comments is array type  
	if(is_array($arraymsg))  
	{  
		//Two String concatenate message with datetime  
	foreach($arraymsg as $message)  
	$stmntEntry.=$Data_arLog['event_datetime']." ".$message."rn";  
}  
else  
{   //concatenate message with datetime  
	
	$stmntEntry.=$Data_arLog['event_datetime']." ".$arraymsg."rn";  
}  
//make file with current date name  
$stCurLogFileName='log_'.date('Ymd').'.txt'; 
 
//open the file append mode,dats the log file will make day wise  
$fileHandle=fopen(LOG_PATH.$stCurLogFileName,'a+');  

//write the info into the file  
fwrite($fileHandle,$stmntEntry);  


//close handler  
fclose($fileHandle);  
}  

how to call use PHP text-file log function in your web-application

//Write a string to a file using PHP
live_log("Sorry,You following ERROR: ".$fault->faultcode."-".$fault->faultstring); 

We hope you get an idea about Write a string to a file using PHP
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.

Read Also:  vuejs crud Insert Update Delete operations Example and demo

We hope This Post can help you…….Good Luck!.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  PHP Laravel 7 Send Email Example Tutorial
  2. Read Also:  Laravel Selecting and Aliasing Columns in Eloquent's query
  3. Read Also:  jQuery Datatable Server Side Processing with codeigniter
  4. Read Also:  Jquery check if value exists in Array Example
  5. Read Also:  Laravel Group by not working - LIMIT or GROUP BY with prepared statement not working
  6. Read Also:  Bind Array List to Checkboxes using Angular Example
  7. Read Also:  Complete User Registration system using Codeigniter 3
  8. Read Also:  jQuery Datatable Server Side Processing with codeigniter
  9. Read Also:  Bind Array List to Checkboxes using Angular Example
  10. Read Also:  Laravel Selecting and Aliasing Columns in Eloquent's query
Categories Programming, Tips and Tricks Tags create log file in php codeigniter, Creating and writing log files, how to create a logfile in php, how to create activity log in php, how to create error log file in php, How to create logs with PHP, php info log, php logging best practices, php write log file new line, php write log to text file, php write to log file append, Simple Logging with PHP, Write a string to a file using PHP
Post navigation
How to use foreach object keys and values in Node Js?
Exercises During Pregnancy Tips For Normal Delivery

Categories

Ajax (419) AngularJS (359) ASP.NET (61) Bollywood (35) Business (16) Codeigniter (142) C programming (13) CSS (62) Earn Money (50) Education (30) Entertainment (41) Events (14) Google Adsense (58) Government (13) Highcharts (77) Hollywood (34) Interview (18) JavaScript (913) Jobs (25) jQuery (989) Laravel (1008) LifeStyle (31) linux (18) Misc (13) Mysql (873) Mysqli (780) Node.js (34) php (1690) Programming (2195) Python (44) ReactJS (33) SEO (22) Software (16) Software (38) tamilrockers (30) Tech (15) Technology (2206) Tips and Tricks (75) Tools (27) Top10 (109) VueJs (249) Web Technology (28) wordpress (135) World (22) Yii (14)
© 2021 Pakainfo • Developed By Pakainfo.com