Topic: save session data to log file

I created a PHP file with AJAX functions and session data to send to another PHP file which then takes the data and creates a PDF using FPDF and FPDI. The second form never actually opens, since it just creates a PDF and sends that to my browser.

I tried to put logging data in the 2nd file since that is where I want to capture who requested information and what was created.

Is this possible?

I'll be happy to post any code but so far I have been unsuccessful in doing this.

Your help is much appreciated.

I am a newbie at xajax but I have lots of experience with PHP.

Rick

Re: save session data to log file

rickmobley wrote:

I created a PHP file with AJAX functions and session data to send to another PHP file which then takes the data and creates a PDF using FPDF and FPDI. The second form never actually opens, since it just creates a PDF and sends that to my browser.

I tried to put logging data in the 2nd file since that is where I want to capture who requested information and what was created.

Is this possible?

I'll be happy to post any code but so far I have been unsuccessful in doing this.

Your help is much appreciated.

I am a newbie at xajax but I have lots of experience with PHP.

Rick

Any help here?

I have a php function written that creates a log file using fopen, but trying to call it with

        $resp->script("logVisit();");

does nothing. No file created, no error and no joy.

I want to store the data from the post so I have a record of who did what.

Thanks in advance.

Re: save session data to log file

You can put the info in session variables and have the second page access it.

If you want it long term write it to a text file or a MySQL table.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: save session data to log file

edrobinson wrote:

You can put the info in session variables and have the second page access it.

If you want it long term write it to a text file or a MySQL table.

Ed

Thanks for the reply Ed.

I am using session variables to send to a second page, but since that page isn't actually opened in a browser it doesn't appear to work there either.

I'm thinking why it doesn't work is because the second page is used to create a PDF using pdfp and pdfi. Can you point me to an example so I can learn the proper way to do this?

I usually write my logs in CLF format but I could store it in a mySQL table as well.

Rick

Re: save session data to log file

There is not any proper way to do this - whatever suits your needs.

The second page not opening would have no effect on the code being executed.

To log to a text file do something like this:

Code: PHP

...

//Open your log file for write only access

$handle = fopen("mylog.txt", "a");

if (!$handle) die("unable to open log file.";



//Write your session variables to the log file

fwrite($handle, $_SESSION['variable1']);

fwrite($handle, $_SESSION['variable2']);

...

fwrite($handle, $_SESSION['variableN']);



//Close the file...

fclose($handle);

 ...

 

You could probably do the same thing with a CLF formatted file.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: save session data to log file

edrobinson wrote:

There is not any proper way to do this - whatever suits your needs.

The second page not opening would have no effect on the code being executed.

To log to a text file do something like this:

Code: PHP

...

//Open your log file for write only access

$handle = fopen("mylog.txt", "a");

if (!$handle) die("unable to open log file.";



//Write your session variables to the log file

fwrite($handle, $_SESSION['variable1']);

fwrite($handle, $_SESSION['variable2']);

...

fwrite($handle, $_SESSION['variableN']);



//Close the file...

fclose($handle);

 ...

 

You could probably do the same thing with a CLF formatted file.

Ed

Ed,

Thank you for help in getting me over the hump. Your code isn't that far from what I had so I went digging and found that I had a permissions issue that wouldn't let me create the file in the first place. The server was rebuilt about a year ago, and some permissions evidentally didn't get set back. Now that the file is created and has the right perms all is well.

Sometimes we need someone to tell us that "it should work" so we don't get side tracked looking in the wrong place for the problem.

While I have your attention. What tools are you using to check your syntax as you enter code? php sometimes catches me with a misplaced comma, quote or other token and instead of telling me the page is not going to load, I just get the blank screen. That causes me to backtrack my code to see what "I" did wrong.

To protect myself from this, I create a copy test1 test2 test3, so I can just go back a day and pick up from where it last worked. Otherwise, I would spend the entire day entering a few lines, testing... entering a few lines, testing. That is not going to be very productive.

Thanks,
Rick

Re: save session data to log file

Rick,

Glad things are working.

I don't have a syntax checking editor. It would be nice... I work in a test area and give changes to the test server and see where the smoke rises.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.