write logging information to php file

using php,

i want to write
ip address

to a textfile
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
You can write to a file with file_put_contents().

DATETIME information is available in PHP date() or the DateTime class object.

Browser and IP are found in $_SERVER and while not 100% reliable they are mostly useful.  Use phpinfo() and look at the bottom of the output to find the $_SERVER information.
Julian HansenCommented:
Modify the way line is represented and path to $filename as you need
$filename = 'logfile.txt';
$line = sprintf("%s,%s,%s," . PHP_EOL,
 date('Y-m-d h:i:s'), $_SERVER["HTTP_USER_AGENT"], $_SERVER["REMOTE_ADDR"]);
file_put_contents($filename, $line, FILE_APPEND);

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgb192Author Commented:
this saves information in a logfile

Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Ray PaseurCommented:
Julian HansenCommented:
You are welcome - thanks for the points.
rgb192Author Commented:
and thanks for the built in error_log function
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.