Execute PHP file in the background from html page
Please support our PHP advertiser: Free Online Load Test - How many visitors can your web site handle?
![]() |
•
•
Posts: 9
Reputation:
Solved Threads: 0
Hello to everyone and wish for a Happy New Year.
I have an html code from which I want to execute various php files (with various parameters).
Say the html file is called htmlcode.html.
Say one php file is called phpfile1.php and a second php file called phpfile2.php
Everything works fine but the problem is that when the php execution comes to an end, then the web browser turns away from my html page (htmlcode.html) and shows the results of the php file execution (which actually (if there are no warnings) is a blank screen).
I'll try to be more specific.
I have various <form action="phpfile1.php" ...> in html that when a certain <input type="button" ...> is pressed they execute the phpfile1.php.
No php file has any output and is executed in order to run a command in the shell via the exec command or to create an xml file with specific data. I don't actually need a log file to store any output from php file execution, but it would be nice if I could do so.
What I want is to execute the php files in the background, without turning the web browser away from htmlcode.html in order to display the php execution results.
Thank you in advance for your time.
Kostas Theof
I have an html code from which I want to execute various php files (with various parameters).
Say the html file is called htmlcode.html.
Say one php file is called phpfile1.php and a second php file called phpfile2.php
Everything works fine but the problem is that when the php execution comes to an end, then the web browser turns away from my html page (htmlcode.html) and shows the results of the php file execution (which actually (if there are no warnings) is a blank screen).
I'll try to be more specific.
I have various <form action="phpfile1.php" ...> in html that when a certain <input type="button" ...> is pressed they execute the phpfile1.php.
No php file has any output and is executed in order to run a command in the shell via the exec command or to create an xml file with specific data. I don't actually need a log file to store any output from php file execution, but it would be nice if I could do so.
What I want is to execute the php files in the background, without turning the web browser away from htmlcode.html in order to display the php execution results.
Thank you in advance for your time.
Kostas Theof
What you should do when they submit your form to phpfile1.php do a redirect back to the htmlcode.html.
Or you can change the htmlcode to a php file and have your form validate to the same page instead by putting your php on the same page.
I like to keep things seperate so I would do the first way.
header("Location: htmlcode.html");I like to keep things seperate so I would do the first way.
A little clarification goes a long way.
•
•
Posts: 9
Reputation:
Solved Threads: 0
As I'm a novice user I don't know where exactly to add this code:
header("Location: htmlcode.html");
do you mean as a command in the end of each php file?
The current location of all files is in http://localhost/ .
Even if it is so, I'm afraid this would make a refresh to htmlcode.html.
I actually don't want to make any refresh(es) to htmlcode.html as there is a GoogleMap showing some information dynamically created and after any unwanted (not scheduled) refresh some needed information created via JavaScript functions will be deleted. After any refresh those info will start being created again from the beginnig.
I've tried with success to stop the php execution via an event handler:
<INPUT type="submit" value="Submit1" name="Submit1" onMouseOut="if (navigator.appName=='Microsoft Internet Explorer') document.execCommand('Stop'); else window.stop();">
In this case the php execution continues on the background, creates the desired results and does not “disturb” the web browser.
The problem in this case is that if the user does not move the pointer out of the submit button the javascript code does not execute. Another case where the event handler won't work is when the user does not click on the Submit button but just presses the enter key while the specific form is "active" in the web browser.
I tried the event handler onMouseUp but didn't work (possibly because the action of the form starts when Mouse click is up.).
Finally, the form is the following:
<FORM method="post" action="http://localhost/phpfile1.php?param1=5¶m2=1">.
Any suggestions please?
header("Location: htmlcode.html");
do you mean as a command in the end of each php file?
The current location of all files is in http://localhost/ .
Even if it is so, I'm afraid this would make a refresh to htmlcode.html.
I actually don't want to make any refresh(es) to htmlcode.html as there is a GoogleMap showing some information dynamically created and after any unwanted (not scheduled) refresh some needed information created via JavaScript functions will be deleted. After any refresh those info will start being created again from the beginnig.
I've tried with success to stop the php execution via an event handler:
<INPUT type="submit" value="Submit1" name="Submit1" onMouseOut="if (navigator.appName=='Microsoft Internet Explorer') document.execCommand('Stop'); else window.stop();">
In this case the php execution continues on the background, creates the desired results and does not “disturb” the web browser.
The problem in this case is that if the user does not move the pointer out of the submit button the javascript code does not execute. Another case where the event handler won't work is when the user does not click on the Submit button but just presses the enter key while the specific form is "active" in the web browser.
I tried the event handler onMouseUp but didn't work (possibly because the action of the form starts when Mouse click is up.).
Finally, the form is the following:
<FORM method="post" action="http://localhost/phpfile1.php?param1=5¶m2=1">.
Any suggestions please?
•
•
Posts: 9
Reputation:
Solved Threads: 0
The onSubmit event handler didn't work.
I think this handler executes the JavaScript command before the action of the form (in this case the execution of the phpfile1.php).
It's like when we validate the contents of various input fields before executing the action of the form, the validation triggers with the onSubmit event handler.
I don't know if there is a way to start the execution of the php file onSubmit or onMouseDown. Then I could stop it onMouseUp.
(Or start onKeyDown and stop onKeyUp respactively).
I'll try on that direction.
Thaks for your time.
I think this handler executes the JavaScript command before the action of the form (in this case the execution of the phpfile1.php).
It's like when we validate the contents of various input fields before executing the action of the form, the validation triggers with the onSubmit event handler.
I don't know if there is a way to start the execution of the php file onSubmit or onMouseDown. Then I could stop it onMouseUp.
(Or start onKeyDown and stop onKeyUp respactively).
I'll try on that direction.
Thaks for your time.
Sorry I am not very familiar with javascript. I did just check the event is used as onsubmit not onSubmit. But yea I do not think that is what you are looking for anyways.
I totally missed that last lien in your first post saying you didn't want a page refresh. Ignore me, I should go back to sleep and quit messing with other people's posts.
/nap
I totally missed that last lien in your first post saying you didn't want a page refresh. Ignore me, I should go back to sleep and quit messing with other people's posts.
/nap
A little clarification goes a long way.
http://www.w3schools.com/Ajax/ajax_intro.asp
Thats a link to an AJAX tutorial from w3schools, maybe that will be helpful hehe.
Thats a link to an AJAX tutorial from w3schools, maybe that will be helpful hehe.
A little clarification goes a long way.
•
•
Posts: 9
Reputation:
Solved Threads: 0
Thank you for your time DiGSGRL.
I'll check the link http://www.w3schools.com/Ajax/ajax_intro.asp you suggest and, as it seems that my problem will be solved via JavaScript, perhaps I'll post a thread in a JS relevant area.
Thanks.
I'll check the link http://www.w3schools.com/Ajax/ajax_intro.asp you suggest and, as it seems that my problem will be solved via JavaScript, perhaps I'll post a thread in a JS relevant area.
Thanks.
•
•
Posts: 2
Reputation:
Solved Threads: 0
An alternative to a JavaScript resolution (if for whatever reason you want to or even just to have another way) is simply set the target of your form to a hidden frame which is much the way the AJAX lifestyle had its roots before anyone took the collection of things they were already doing and lumped it all together and called it AJAX. If your need is simple then it is possible that a not visible frame would provide a simple solution.
Just write this at the bottom of your php files (like mentioned previously):
or for more generic return code (it will return you to the previous page):
You MUST ensure that no text (error messages or echoed php or any HTML) is output to screen before the header function is called or you will get an error.
<?php header("Location:htmlcode.html");exit; ?>or for more generic return code (it will return you to the previous page):
<?php header("Location:{$_SERVER['HTTP_REFERER']}");exit; ?> Last edited by ardav : Jan 9th, 2009 at 6:50 pm.
![]() |
Similar Threads
Other Threads in the PHP Forum
- dynamic html (PHP)
- Creating an event or an action to a button. (PHP)
- problem in javascript coding in asp page (ASP)
- php adodb library connect remote mysql (PHP)
Other Threads in the PHP Forum
- Previous Thread: Getting the contents of a DIV on another page
- Next Thread: google chekout help
•
•
•
•
Views: 1779 | Replies: 13 | Currently Viewing: 1 (0 members and 1 guests)





Linear Mode