...

View Full Version : Is this how I write an error log file ?



jeddi
09-02-2009, 08:11 PM
Hi,

I am trying to make my paypal form work and
it looks like I need to create a "paper trail" of the
script progress.

Normally I would do it with echoes so that I can
see where it gets to on the screen, but when doing a live payment,
I don't get the screen echos because it is the paypal server
that is running my script.

So what I need to do is open a file and store my echos statements in it.

So open a file do I just use:


$log_file = $_SERVER['DOCUMENT_ROOT']."/log.txt";
$handle = fopen("$log_file", "w");


and then write something


$content = "The script got here";
fwrite($handle, $content);

If the script fails somewhere, then I may not
be able to close the file with the fclose($handle);
statement. - Is that a problem ?

Is there anything else that I need to do ?

Thanks for any guidance.

CFMaBiSmAd
09-02-2009, 08:20 PM
http://us.php.net/manual/en/function.error-log.php

jeddi
09-03-2009, 06:00 AM
Thanks for the advice.

The error logs do help but because the script is not
behaving as I expected, I also need to find out the value
of some of the variables.

So normally I would just write:
echo "Txn_type: $txn_type";

I have not done much plain text handling so I just wanted
to know if what I had written for my log file was correct.

I realise that it will get over written each time, but that is ok

So open a file do I just use:



$log_file = $_SERVER['DOCUMENT_ROOT']."/log.txt";
$handle = fopen("$log_file", "w");

and then to write my variables



$content = "Txn_type: $txn_type";
fwrite($handle, $content);


If the script fails somewhere, then I may not
be able to close the file with the fclose($handle);
statement.

- Is that a problem ?


Is there anything else that I need to do ?

Thanks

djm0219
09-03-2009, 10:24 AM
If the file is open when PHP exits it should be closed for you.

jeddi
09-03-2009, 12:20 PM
So I guess that the rest is ok ?

To write end-of-line do I use /n ?
or is it \n ?

Do I just insert it at the end of my text like this ?


$content = "Txn_type: $txn_type \n";

How can I read the file ?

Can I just open it with Notepad ?

Thanks for helping.

djm0219
09-03-2009, 02:41 PM
\n is for a new line and \r\n is for carriage return and a new line. Both must be used within double quotes for them to work. Any editor should be able to open a .txt file.

jeddi
09-04-2009, 11:05 AM
Thanks

Its working great :thumbsup:

jeddi
09-04-2009, 11:57 AM
Oops! I spoke too soon.

It works fine when I run the script from my browser.

Nah - MY BAD.

It is OK now. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum