By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,051 Members | 1,198 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,051 IT Pros & Developers. It's quick & easy.

Button to execute python script

P: n/a
Hi

I am pretty new to PHP and hence need your help!!

I need to write a PHP that shows the user a button (button1) and a
series of check boxes and another button (button2)..

If the button1 is clicked then I should launch a python script running
on the same linux box as the PHP..

If any of the check boxes are checked and button 2 is clicked, then I
should launch another script..

Is there any way to do this in PHP...

Thanks

Feb 1 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Thu, 01 Feb 2007 11:34:07 -0800, elrondrules wrote:
I am pretty new to PHP and hence need your help!!

I need to write a PHP that shows the user a button (button1) and a
series of check boxes and another button (button2)..

If the button1 is clicked then I should launch a python script running
on the same linux box as the PHP..

If any of the check boxes are checked and button 2 is clicked, then I
should launch another script..

Is there any way to do this in PHP...
No. PHP is a server-side scripting language.

You need to use a client-side scripting language like JavaScript.
Feb 1 '07 #2

P: n/a
"Ivan Marsh" <an*****@you.nowwrote in message
news:pa****************************@you.now...
On Thu, 01 Feb 2007 11:34:07 -0800, elrondrules wrote:
>I am pretty new to PHP and hence need your help!!

I need to write a PHP that shows the user a button (button1) and a
series of check boxes and another button (button2)..

If the button1 is clicked then I should launch a python script running
on the same linux box as the PHP..

If any of the check boxes are checked and button 2 is clicked, then I
should launch another script..

Is there any way to do this in PHP...

No. PHP is a server-side scripting language.

You need to use a client-side scripting language like JavaScript.
I don't think Ivan understood correctly, because it most certainly can be
done with php at the server. Just call the python script via exec() or
system() in the form handler, once you've detected that the button was
clicked.

<form action="execute_python.php" method="post">
<input type="submit" name="submit1" />
</form>

<form action="execute_python.php" method="post">
checkboxeses:
<input type="checkbox" name="foo1" />
<input type="checkbox" name="foo2" />
<input type="checkbox" name="foo3" />
<input type="checkbox" name="foo4" />
<input type="submit" name="submit2" />
</form>

execute_python.php should be something like

<?php
if(isset($_POST['submit1'])){
exec('/path/to/the/python/script/my_python.py');
}
if(isset($_POST['submit2'])){
exec('/path/to/the/python/script/my_other_python.py');
}
?>

Read more about command line and php:
http://fi2.php.net/manual/en/ref.exec.php

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Feb 2 '07 #3

P: n/a
el*********@gmail.com wrote:
Hi

I am pretty new to PHP and hence need your help!!

I need to write a PHP that shows the user a button (button1) and a
series of check boxes and another button (button2)..

If the button1 is clicked then I should launch a python script running
on the same linux box as the PHP..

If any of the check boxes are checked and button 2 is clicked, then I
should launch another script..

Is there any way to do this in PHP...

Thanks
Yes, as Kimmo mentioned you could just exec to a server-side Python
script, but one wonders, since you're going back to the server anyway,
why you're switching languages...

(Just to be clear, here, Ivan is also right: You can't "run" Python in
the browser as it is a server-side language, and the form is living in
the browser, i.e., the client. For the Python script to run, that
information has to be transmitted from the client back to the server, so
the server knows to run the Python code...)
Feb 3 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.