I'm developing a Web Application and I got stuck at this:
I want to create a simple tag that triggers the execution of a local program
such as gedit, mozilla firefox, etc.
My project is based on HTML, Javascript and PHP.
I'm aware that Javascript doesn't allow this kind of execution, but perhaps PHP does?
Thank you!
PHP code runs on the server; it has no influence over what happens in the web browser. All it can do is generate HTML and Javascript for the web browser to process, it can't take any action on the client machine directly, so no, there's no way to do this.
You can do that with exec() function but the program has beign executed on the server doesnt on the client side
Related
Is it possible to make a php code on a webpage send out a code that the visitor will run? Like:
<?php
batch("echo text");
?>
Then it will open a cmd window that says text. If it does not work in php does it work in another launge?
PHP runs on a server and has no magical control over what happens on someone else's computer. Once the page has loaded it will be send to the requester's browser.
From there you have access to some local storage/cookies/etc., but only what the browser provides to you. If the browser would give a website access to the cmd, it would mean that any website could simply read pretty much everything on anyone's computer, or do harm in many other ways. You can imagine that this is not really secure.
The only way you can execute batch commands on someone's computer is if you or your program have access to that computer. In other words, the user must download your batch/.exe file and run it manually.
In my project I have to do some screen scrapping.The source pages return data after executing the javascript embedded within them.In my php script I fetch the page using file_get_contents() and as usual,it returns the page simply as text.My question is that,is there a way to get the final output from the webpage (the output after executing javascript).
I know some of you might suggest embedding a webbrowser inside and using that to execute the page.But how to do that?.Is there a working browser available.Or is there executable non GUI versions of opensource browsers such as chromium,so that I can run it as a CGI script or something
You will have to have some real browser like client for this, php alone won't cut it. For automation purposes you are most likely want a "headless" (without gui) browser like PhantomJS (the new hotness). Check out this answer.
I need to run a javascript code on server side using IE8
(the javascript works with activeX objects)
But I need to run it from command line, from PHP.
So in short, I will install apache + php on 2003 Windows server, and php will use system() to execute iexplore running a page of javascript.
I would like to know if this is logically possible, as i can see a number of pitfalls:
PHP might not be able to execute iexplore without a user logged in.
iexplore might not run the javascript correctly to interact with ActiveX objects
iexplore might not quit when JS finished running.
I will attepmt to make a little test case as soon as i can, but any pointers about this aproach will be apreciated.
Edit:
Now, I realise that this is a round about way of doing things (read, wrong), The goal was to make a Dymo Label printer print from a central location rather than client machines (this is where the JS is from). Dymo SDK provide several ways of interacting with their printers, but Im still looking for a way to use pure PHP. I think it might be possible to use one of their example cli binaries.
Does the Dymo have a way of interacting with it from Command Line? If so you can easily send commands to it via shell_exec(). http://www.php.net/manual/en/function.shell-exec.php
This is generally the easiest option when you are able to control something via command-line. Sometimes you need a bit more control, however (interactive command-line programs, for instance) and sometimes the program you want to run isn't even command-line based. In these cases you may need proc_open() (http://www.php.net/manual/en/function.proc-open.php) or exec() (http://www.php.net/manual/en/function.exec.php)
Just make sure that if you use exec() you redirect the output!!. Failure to do this can cause the program to hang indefinitely.
From the PHP manual:
Note:
If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
Make sure to update your Service Packs and AntiVirus definitions. I can foresee many many many potential security issues here.
Keep in mind that JavaScript in IE runs with a webpage context. When you refresh/navigate pages, the old JavaScript execution state is wiped and a new one begins.
Was there a specific question here?
I have a server with a PHP script that pulls data from a source and populates a database. I need to call this PHP script repeatedly, each time with a different parameter.
I need to create a shell script on a Mac (which reads in a text file with the list of parameters - that part is not a problem) and for each parameter, runs the PHP script/URL in a web browser.
The PHP is on a remote server, so I need to load a web browser instance (safari or firefox) and instruct it to load the URL (ie. something like http:/myserver.com/scriptname.php?param1). Then I need to wait for it to complete and trigger the same URL with the next parameter.
I don't know the incantation to launch the web browser with a URL (I am a former Windows dev not a Mac OS-X pro, yet). I also don't think there is a way to detect when the script completes - but I don't want to end up with 100 instances of the browser running simultaneously.
Any help would be greatly appreciated!
If you just need it to hit a php page on a remote server, don't use a browser. Use curl, or some equivalent.
curl http:/myserver.com/scriptname.php?param1
open -a Safari http://stackoverflow.com
I'm trying to integrate an old PHP ad management system into a (Django) Python-based web application. The PHP and the Python code are both installed on the same hosts, PHP is executed by mod_php5 and Python through mod_wsgi, usually.
Now I wonder what's the best way to call this PHP ad management code from within my Python code in a most efficient manner (the ad management code has to be called multiple times for each page)?
The solutions I came up with so far, are the following:
Write SOAP interface in PHP for the ad management code and write a SOAP client in Python which then calls the appropriate functions.
The problem I see is, that will slow down the execution of the Python code considerably, since for each page served, multiple SOAP client requests are necessary in the background.
Call the PHP code through os.execvp() or subprocess.Popen() using PHP command line interface.
The problem here is that the PHP code makes use of the Apache environment ($_SERVER vars and other superglobals). I'm not sure if this can be simulated correctly.
Rewrite the ad management code in Python.
This will probably be the last resort. This ad management code just runs and runs, and there is no one remaining who wrote a piece of code for this :) I'd be quite afraid to do this ;)
Any other ideas or hints how this can be done?
Thanks.
How about using AJAX from the browser to load the ads?
For instance (using JQuery):
$(document).ready(function() { $("#apageelement").load("/phpapp/getads.php"); })
This allows you to keep you app almost completely separate from the PHP app.
Best solution is to use server side includes. Most webservers support this.
For example this is how it would be done in nginx:
<!--# include virtual="http://localhost:8080/phpapp/getads.php" -->
Your webserver would then dynamically request from your php backend, and insert it into the response that goes to the client. No javascript necessary, and entirely transparent.
You could also use a borderless <iframe>
I've done this in the past by serving the PHP portions directly via Apache. You could either put them in with your media files, (/site_media/php/) or if you prefer to use something more lightweight for your media server (like lighttpd), you can set up another portion of the site that goes through apache with PHP enabled.
From there, you can either take the ajax route in your templates, or you can load the PHP from your views using urllib(2) or httplib(2). Better yet, wrap the urllib2 call in a templatetag, and call that in your templates.