Author |
|
donnpe
Joined: 21 Apr 2010 Posts: 3 Location: London
|
Posted: Wed 21 Apr '10 9:38 Post subject: Problem with php include function on localhost apache2.2 |
|
|
Hi
I am having problems getting the PHP include function working on my new Apache2.2 installation on my new laptop (locahost).
My standard PHP files work fine (e.g. phpinfo() shows everything is good) however if I have a file – e.g. testinclude.php below, which includes another file on localhost, I get a browser error. Including a file on another server is fine:
This works - i.e. when including page on another server:
<?php
include("http://"."www.hertsholistichealth.co.uk"."/testpage.html);
?>
This includes a file on localhost and produces an error when entered into the browser:
<?php
include("http://localhost/testpage.html"); // Produces browser error below
?>
Error when entering http://locahost/testinclude.php into browser:
Warning: include(http://localhost/testpage.html) [function.include]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. In C:\Users\peter\Documents\WebSites\HHH\testinclude.php on line 3
I would greatly appreciate any help on what could be going wrong with the localhost include.
Thanks
Peter |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 21 Apr '10 10:07 Post subject: |
|
|
on your local server you should open an include with a relative path or the file system path.
e.g.
Code: |
include 'include.php'; //better choise
include 'C:/users/peter/Documents/WebSites/HHH/testinclude.php'; // only if the file is outer the document root.
|
if HHH is your Document root a relative include is always the better choise.
Open an url with include? For that you should use file_get_contents or fopen. |
|
Back to top |
|
donnpe
Joined: 21 Apr 2010 Posts: 3 Location: London
|
Posted: Wed 21 Apr '10 10:27 Post subject: Re: Problem with php include function on localhost apache2.2 |
|
|
Hi
Actually your suggestion did work, however I want a generic include to work both on localhost and also on my web server when I upload it. So I am actually using:
include("http://".$_SERVER["HTTP_HOST"]."/testinclude.php");
When I use file_get_content I get the same error.
Thanks
Peter |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 21 Apr '10 11:26 Post subject: |
|
|
As I told before, use the relativ path! That will work on your local server and on the external server. |
|
Back to top |
|
donnpe
Joined: 21 Apr 2010 Posts: 3 Location: London
|
Posted: Wed 21 Apr '10 11:52 Post subject: Re: Problem with php include function on localhost apache2.2 |
|
|
Hi
The issue is that it needs to be a URL as I have a query string. In my real code the line actually is:
include("http://".$_SERVER["HTTP_HOST"]."/services/php/serviceDetails.php?selectlabel=Acupuncture&service_ID=78");
I assume that I can't use the relative path in that case?
Many thanks
Peter |
|
Back to top |
|
wm003
Joined: 24 Mar 2006 Posts: 88
|
Posted: Wed 21 Apr '10 13:22 Post subject: |
|
|
There is no issue. if you really want to let servicedetails.php parse get parameters then just add them
Code: |
$_GET["selectlabel"] = "Acupuncture";
$_GET["service_ID"]=78;
include("/services/php/serviceDetails.php"); |
|
|
Back to top |
|
hakunam
Joined: 18 Apr 2011 Posts: 1
|
Posted: Mon 18 Apr '11 13:29 Post subject: |
|
|
Also check your ini settings what you want is pretty easy everybody does it.. |
|
Back to top |
|
vegitaboss
Joined: 06 Nov 2011 Posts: 2
|
Posted: Sun 06 Nov '11 5:53 Post subject: |
|
|
It worked for me
Code: | include 'include.php'; //better choise
include 'C:/users/peter/Documents/WebSites/HHH/testinclude.php'; // only if the file is outer the document root. |
|
|
Back to top |
|