Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Is this how I write an error log file ?

    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:

    PHP Code:
    $log_file $_SERVER['DOCUMENT_ROOT']."/log.txt"
    $handle fopen("$log_file""w"); 
    and then write something

    PHP Code:
    $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.

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    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:


    PHP Code:
    $log_file $_SERVER['DOCUMENT_ROOT']."/log.txt"
    $handle fopen("$log_file""w"); 
    and then to write my variables

    PHP Code:
    $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

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    If the file is open when PHP exits it should be closed for you.
    Dave .... HostMonster for all of your hosting needs

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    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 ?

    PHP Code:
    $content "Txn_type: $txn_type \n"
    How can I read the file ?

    Can I just open it with Notepad ?

    Thanks for helping.

  • #6
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    \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.
    Dave .... HostMonster for all of your hosting needs

  • #7
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks

    Its working great

  • #8
    Senior Coder
    Join Date
    May 2006
    Posts
    1,683
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Oops! I spoke too soon.

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

    Nah - MY BAD.

    It is OK now.
    Last edited by jeddi; 09-04-2009 at 12:14 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •