I have a PC connected to a Raspberry via an Ethernet network. In Raspberry there is the file Stb.php in directory /var/www/ the IP of Raspberry is 192.168.1.15.
I like to use a function in file Stb.php named sendScreenCommand from my server which installed in my PC.
Here is my code but it is not working:
include 'http://192.168.1.15/Stb.php';
$command="mkdir /flash/Resources/resources"
sendScreenCommand($command);
You can enable allow_url_include in your php.ini configuration file.
Doing this is strongly discouraged, as it can present serious security risks.
You cannot do it like that. The path you are using is a url on a web-server and according to the manual:
This is not strictly speaking the same thing as including the file and
having it inherit the parent file's variable scope; the script is
actually being run on the remote server and the result is then being
included into the local script.
So your php file is being parsed / executed on the Raspberry and all you get back are the results so there are not functions to execute.
Unless Stb.php outputs php code of course, but that seems very unlikely from what I understand from the question...
If this is on a local network, you could make it work if you can mount the file-system of the Raspberry on your pc so that you can use a file path like for example:
include '/mnt/Raspberry/Stb.php';
(assuming something like linux or OSX, on Windows it would be a bit different)
Related
I have installed an apache webserver on Linux Debian and created an intranet on it. The intranet basically shows tables with entries from sql queries via php and mysql.
In one of these tables I would like to add a hyperlink that leads to/opens files and folders on a remote windows server.
I can access these files on the windows server from my linux webserver via cifs protocol.
How do I tell apache and/or linux where they need to go when a user clicks on a hyperlink in my intranet?
The path for the windows server is: \10.0.10.100\data\moredata\file.xls
I can access the windows server folders on my linux webserver via the following path: /media/data/moredata/file.xls
However, if I place this path inside html tag like this:
open my file please , it won't work.
If I try it like this: open my file please , it also won't work.
I believe that I need to insert the path inside apache.conf ? Is this correct? And if so, how is it done exactly?
You have to create Alias for that. Like 10.0.10.100/media can be pointing to your root /media folder. You can do it in your config file. Hope this link can help.
My problem is that I can't include a file on a remote server.
<?php
echo "Including\n";
require_once("http://xx.xxx.xxx.xx:8080/path/to/myfile.inc");
echo "Done..\n";
?>
The script fails at the require_once function.
I'm running the script with: php -d allow_url_include=On script.php
but to make sure I have set allow_url_include and allow_url_fopen to On in php.ini
If I copy http://xx.xxx.xxx.xx:8080/path/to/myfile.inc to the browser I'm served the file.
I have also tried to include other remote files (on standard port 80), but still no luck
Where I get really confused is that everything works from my local computers at my office (mac, ubuntu), but not from our servers. I have tested it on 2 different servers, a virtual and a dedicated.
I can get the file with fopen().
This can be done by setting allow_url_include to on on php.ini.
But, as mentioned in comments, this opens a
huge
security hole on your application.
Require_Once should be used for local files only. If you want to get a remote file use file_get_contents. Remember if you are trying to include php from a remote server like that, it will be really insecure or the php will be executed on the remote server.
question is how to give command line (in .cmd script) to execute browser to then in turn have browser execute .php script.
Presently if from a command window I execute like ...
"c:\Program Files\Internet Explorer\iexplore.exe" file:\c:\users\win7ultsdtest\findroot.php
....OR....
C:\Program Files\Internet Explorer\iexplore c:\users\win7ultsdtest\findroot.php
This will run the Explorer browser, but then the browser the browser will download the contents of findroot.php instead of executing the php code as I need. Does anyone know how I can get the browser to instead execute the php code and not just download it as data?
Let me explain my need ... The findroot.php file contains php code to access the $_SERVER['DOCUMENT_ROOT'] variable. This variable is ONLY non-null when the localhost is running a http server and then it contains the localhost document server root path where loadable browser .html, .php etc may be stored to loaded from http:\ lines.
The findroot.php outputs the $_SERVER['DOCUMENT_ROOT'] contents to a file as rootpath.txt so that my .cmd script can then can automatically install PHP code into the active PHP servers document root area.
So understand I must find the $_SERVER['DOCUMENT_ROOT'] from a .cmd script.
Now I might search ALL the computers drives for httpd.conf and then scan that file for the value but this wouldn't work for two reasons; 1. there can be multiple httpd.conf files and I can't know which server is active and using what httpd.conf. 2. it would take a long time to search a given computers entire drive(s) on all httpd.conf files.
The browser won't execute PHP code. You either need a server to run PHP and to access it via HTTP such as C:\Program Files\Internet Explorer\iexplore http://localhost/url/for/findroot.php or you can run PHP via the command line c:\path\to\php.exe c:\users\win7ultsdtest\findroot.php. However running it via the command line won't give you $_SERVER['DOCUMENT_ROOT'] as that is only populated when running PHP within a server.
It's not possible to execute PHP by the HTTP server without the server knowing about the PHP before hand - for example, by being in the document root. Of course if you don't know the document root, your script won't be there. If you're trying to install a script into a web server for a user, it's much better to give instructions on how to do so as their server environment will likely vary from what you expect.
There are light browsers like lynx if you are in a linux machine
lynx http://whateverurl/php.php
I was experimenting with shell_exec and commands, and I can't seem to get this work. Im using the php shell_exec() function and running a screen capture command to take a snapshot of the desktop. When running the script locally through coda, it works fine. Then i ran it through my installion of apache through htdocs, and it runs, yet it doesn't save the image anywhere? For browsers, do i need to change the directory at all? this is what my super simple script looks like. Is this even possible?
<?
$command = "screencapture -iWP ~/Random/test.png";
shell_exec($command);
?>
I don't currently have access to a Mac to test, but I'd be extremely surprised and more than a little concerned if that did work.
On the server, apache should be running under a different user ID to the logged in user, which means the attempt to grab the framebuffer should fail.
If it did at least write (or try to write) an image, then it will be ~/Random/test.png; e.g. if apache runs as a user called apache, the target filename is ~apache/Random/test.png
OSX is basically UNIX, and a key feature of UNIX-like operating systems is security. The video framebuffer should only be accessible to processes running under the UID of the logged in user (or root). Daemon processes like apache httpd should be running under their own, non-root UID.
You probably have to specify the full path of the executable. Also, specifying the full path of the output PNG would help too because they're different users.
Run the command
which screencapture
To find the path that the executable is located in. The output file must be in a writable directory for the user that apache is running under (usually apache). You can check the user that apache is running under by looking in the apache configuration, or just running "top" (as root).
Hope that helps.
I'm a little bit confused about the Windows System %PATH% variable. When I ran the following script with both, php-cli and as a webpage delivered by apache, I get different output for the path variable.
// different output for php-cli and php executed by apache webserver
<?php
system('echo %PATH%');
?>
Where can I change the PATH variable that is in use with the apache webserver?
My system:
Win7 64bit
Zend Server Community Edition 5.0.4 (with Apache, not IIS)
Edit:
Sorry, I had to give you an example to understand the problem:
I wanted to exec the system('mysqldump .....') command or something like that. The point is, running the script from the command line works, because the MySQL bin path is in the system's path but running the script via webbrowser doesn't include the MySQL bin path in the system's path.
The web system's path is:
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\Programme\Sysinternals;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Zend\ZendServer\bin
Bit the original system's path is much longer. My question is now, where is the system's path limited or where can I find the system's path settings for the web executed php script?
Try using the following instead,
echo getenv('PATH')
See at C:\Path\To\Zend\ZendServer\ZendEnablerConf.xml.
There is a path variable definied.
Environment variables are per-process in Windows; they are (usually) inherited from the parent process, with the top process setting PATH to the system-wide path plus the per-user path. Therefore, if you are running CLI version of PHP under your user account, the path will contain your user-defined path, while the Apache process running under a service account will get only the system-wide path.
You can set the system-wide path in System Properties (Control Panel\System and Maintenance\System), Advanced, Environment Variables. Or, I believe you can set the environment variable in Apache, e.g. using mod_env and the SetEnv directive.