logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: Problem with php include function on localhost apache2.2
Author
donnpe



Joined: 21 Apr 2010
Posts: 3
Location: London

PostPosted: Wed 21 Apr '10 9:38    Post subject: Problem with php include function on localhost apache2.2 Reply with quote

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

PostPosted: Wed 21 Apr '10 10:07    Post subject: Reply with quote

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

PostPosted: Wed 21 Apr '10 10:27    Post subject: Re: Problem with php include function on localhost apache2.2 Reply with quote

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

PostPosted: Wed 21 Apr '10 11:26    Post subject: Reply with quote

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

PostPosted: Wed 21 Apr '10 11:52    Post subject: Re: Problem with php include function on localhost apache2.2 Reply with quote

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

PostPosted: Wed 21 Apr '10 13:22    Post subject: Reply with quote

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

PostPosted: Mon 18 Apr '11 13:29    Post subject: Reply with quote

Also check your ini settings what you want is pretty easy everybody does it..
Back to top
vegitaboss



Joined: 06 Nov 2011
Posts: 2

PostPosted: Sun 06 Nov '11 5:53    Post subject: Reply with quote

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


Reply to topic   Topic: Problem with php include function on localhost apache2.2 View previous topic :: View next topic
Post new topic   Forum Index -> Other Software