Page 1 of 1

PHP run python code

Posted: Tue Jun 16, 2015 5:24 am
by izzakh
hi there.. im having this python scripts snippet:

import webbrowser

url = 'http://idiotinside.com'

# Open URL in new browser window
webbrowser.open_new(url) # opens in default browser

# Opens in mozila browser
webbrowser.get('firefox').open_new_tab(url)



and PHP code to execute the python:
exec('C:\Python27\python.exe C:\xampp\htdocs\wd\launch_ff.py');

but it seems firefox is not launched.

Need help!!

Re: PHP run python code

Posted: Tue Jun 16, 2015 1:37 pm
by Christopher
Where do you expect it to launch Firefox? PHP runs on the server, so it will open a process and run Firefox there and then terminate the process.

Re: PHP run python code

Posted: Tue Jun 16, 2015 7:56 pm
by izzakh
i want to launch Firefox in my local after execute the script. is that possible?

Re: PHP run python code

Posted: Tue Jun 16, 2015 9:58 pm
by Christopher
You can run Firefox on the server, but it is run by the web server process. And Firefox should exit when the script exits. What is it you are trying to do?

You want to launch Firefox from a web page? How about:

<a href="mypage.php" target="_blank">Open Firefox</a>

Re: PHP run python code

Posted: Wed Jun 17, 2015 1:14 am
by izzakh
Here is what my code is working:
1. launch firefox with urls taken from database..there will be multiple windows of firefox browser once the code is executed.
2. Firefox will exit once all url are loaded.

The objective of launching url into browser is for firebug add-on in the browser to analyse the url page.

Re: PHP run python code

Posted: Wed Jun 17, 2015 9:16 am
by Christopher
Why not just use Javascript to open a window?