I'm trying to include a file with an absolute url:
<?
session_start();
$_SESSION['sr_path'] = 'http://domain.org/www/myapp';
include($_SESSION['sr_path'].'/assets/contact.php');
?>
But it don't work.
Any idea why please ?
I'm trying to include a file with an absolute url:
<?
session_start();
$_SESSION['sr_path'] = 'http://domain.org/www/myapp';
include($_SESSION['sr_path'].'/assets/contact.php');
?>
But it don't work.
Any idea why please ?
you include your files by directories not url:
include(dirname(__FILE__).'/assets/contact.php');
or
include(dirname(__FILE__).'/contact.php');
where dirname(__FILE__) get the path of your current file you write this code in it.
or for all case you can define constant in your website index.php page, and use this const anywhere:
define('ROOT', dirname(__FILE__));
then use it in any dir like this:
include(dirname(__FILE__).'/same_index_file_path/contact.php');
You are currently attempting to include a file by a URL not by the path on the server. By default you cannot use the 'HTTP' wrapper or you'll get this warning (or similar):
http:// wrapper is disabled in the server configuration by allow_url_include=0
Whilst you can include files by URL, it is generally preferred to include with a path on your server.
If you did want to go ahead with your current method and include something which is stored on a different server to the one the script is running on, you'll need to update your configuration by setting 'allow_url_include' to 1.
The PHP Docs for include specify:
If "URL include wrappers" are enabled in PHP, you can specify the file to be included using a URL (via HTTP or other supported wrapper - see Supported Protocols and Wrappers for a list of protocols) instead of a local pathname.
It's worth noting, however, that if you use HTTP you could be relying on a remote server to process the PHP script for you and return it to your script. As the docs state:
Remote file may be processed at the remote server (depending on the file extension and the fact if the remote server runs PHP or not) but it still has to produce a valid PHP script because it will be processed at the local server.
It goes onto clarify:
...the script is actually being run on the remote server and the result is then being included into the local script.
TL;DR
I would guess what you actually want to do, assuming the script you are attempting to include is on the same server as the script that is doing the including, is to just give the path to it on your server such as:
/var/www/myapp/assets/contact.php
which would look like this:
include('/var/www/myapp/assets/contact.php');
instead of this:
include('http://example.com/myapp/assets/contact.php');