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.
Related
I'm trying to download a file locally from a remote server but every time i access the file that contains the PHP code using the browser file_get_contents() fails because it doesn't have the permission to write to /var/www/html (Apache2). I tried using cURL but that didn't work either, checked to see if allow_url_fopen is on (it is) and added the php file to sudoers. I can't seem to find any solution online.
i think this is permission issue, see this maybe will solve your problem, pick that suit to your enviroment.
I'm using sftp to reach my folder on a server at uni. Both chrome and firefox would download my simple test.php instead of opening the page.
Is there any suggestion where should I look with the preferences to change this? (Ubuntu 16.04)
Oh, okay I understand it now, my bad.
I literally mounted the server to my local machine with ssh, thus I had no server whatsoever.
I had to reach directly with the url to open it, so I couldn't just open it from editor (VS Code - open with browser).
Your webserver isnt passing the php file to php for processing and is just sending it on as it would any other file. You will need to ensure that your webserver is setup to handle php correctly be it php-fpm for apache and nginx or the php module for apache
What's the webserver? You can start to read here: http://php.net/manual/en/install.php
I started a PHP project few days back. It works perfectly fine on my localhost. But after I uploaded my files on Godaddy (Plesk) server, a few scripts are not working. I used cURL for the pages and I am guessing that cURL is disabled on the server. I tried to find the php.ini file on the server, but could not locate it.
Also after following a few threads here, I created a php.ini file in the root directory of the server by copying it from my local server. It did not work. I don't know if I did something wrong here. Is there a way to enable cURL on the server, or to access the php.ini file or any procedure to create my own ini file?
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)
I have installed fresh LAMP on Ubuntu 13.10 After installation PHP works fine if i put the PHP code to default localhost web folder /var/www
I created the virtual host. I did it as usually before and never had problems
I added the file to /etc/apache2/mods-enabled and activated
but then when i enter this virtual host in browser i can see the code of my index.php file in the browser.
Also when i execute php code from command line i can see source of the code and it is not executed.
What can this be?
Try to use <?php and ?> not short tags, or if you want really use that (their use is discouraged due to compatibility issues), ensure that php.ini configuration have:
short_open_tag=On