| | |
Execute PHP file in the background from html page
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2009
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.
PHP Syntax (Toggle Plain Text)
header("Location: htmlcode.html");
I like to keep things seperate so I would do the first way.
A little clarification goes a long way.
•
•
Join Date: Jan 2009
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?
•
•
Join Date: Jan 2009
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.
•
•
Join Date: Jan 2009
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.
•
•
Join Date: Dec 2008
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 Syntax (Toggle Plain Text)
<?php header("Location:htmlcode.html");exit; ?>
or for more generic return code (it will return you to the previous page):
PHP Syntax (Toggle Plain Text)
<?php header("Location:{$_SERVER['HTTP_REFERER']}");exit; ?>
Last edited by ardav; Jan 9th, 2009 at 7:50 pm.
![]() |
Similar Threads
- 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
| Thread Tools | Search this Thread |
advanced alerts apache api archive array autosuggest beginner binary broken cakephp checkbox class clients cms code cron curl database date datepart display dynamic echo email emptydisplayvalue eregi error execute explodefunction file files folder form forms function functions google hack head href htaccess html if...loop image include insert ip javasciptvalidation javascript joomla keywords library limit link login mail matching menu mlm multiple mysql number object oop password paypal pdf php phpincludeissue query radio random recursive remote script search searchbox server sessions shot smarty source space speed sql syntax system table tutorial update upload url validator variable vbulletin video web website youtube





