DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   Execute PHP file in the background from html page (http://www.daniweb.com/forums/thread165958.html)

Kostas Theof Jan 9th, 2009 9:52 pm
Re: Execute PHP file in the background from html page
 
Thank you ardav and robert_c_guy, I'll check what you suggest as soon as possible.

Is it possible by the way that the output of the php file gets stored in an external log file? (Either by appending new info about warnings, errors, normal output etc, or by replacing each time the existing log file with the new output? You see, this might be helpful sometimes.)

Thanks.

almostbob Jan 9th, 2009 11:10 pm
Re: Execute PHP file in the background from html page
 
$output = bla blah bla; /* the data output from the background php page. I had to put SOMETHING here, */
$getdate = date( 'd-m-Y, H:i:s' );// Get the date.
$user_ip = $_SERVER['REMOTE_ADDR'];// Get the user IP, just in case.
$referer = getenv("HTTP_REFERER");// Get the refering page. just in case
$file = "./your path to logfile/logfile.csv"; /*define the file as required, csv opens easily in excell or imports to sql if REQ, but is really just a text file.*/
$fp = fopen($file, "a+"); //open the text file for writing.
// Write into the text file.
fputs ($fp, "$getdate, $user_ip, $referer, $output\n"); //see note after $output definition above
fclose($fp);// Close the text file.
create a blank text file logfile.csv (or whatever), this scrap is just an appendage to the existing page, not optimized, just an example, there can be any number of data fields to comprise
 $output

mschroeder Jan 10th, 2009 2:30 am
Re: Execute PHP file in the background from html page
 
Seems i am a bit late to the game, but your problem definitely lends itself to using AJAX.

and it would be a rather simple solution at that.
Although instead of recommending you learn AJAX from scratch, I'm going to point you to the prototype library http://www.prototypejs.org/ I'm sure you've probably heard of it.

Now,as far as working with prototype, I think the most all encompassing tutorial I have ever seen has to be this one http://www.phpriot.com/series/8-weeks-of-prototype

If you browse through those 8 lessons you'll have a pretty sound understanding of how it all works and comes together.

ardav Jan 11th, 2009 8:21 am
Re: Execute PHP file in the background from html page
 
Nice tutorial link. I agree if you don't want to leave/return to the html page, use Ajax. I use prototype myself and it's REALLY easy, and I don't even do JS that well.


All times are GMT -4. The time now is 10:46 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC