Greenguy's Board

Greenguy's Board (http://www.greenguysboard.com/board/index.php)
-   Programming & Scripting (http://www.greenguysboard.com/board/forumdisplay.php?f=15)
-   -   Getting Relative PHP Includes to Work Locally. (http://www.greenguysboard.com/board/showthread.php?t=36120)

Jeremy 2006-11-15 05:30 PM

Getting Relative PHP Includes to Work Locally.
 
Hmmmmmm this is a real teaser for me, even though I'm sure the answer is bllindingly simple!

I'm using WinXP Home, Apache/2.0.55 (Win32) PHP/5.1.4.

PHP & Apache seems to work fine on my PC with the exception of one annoying thing..... I can't get relative php includes to work if they reference root!

eg include ('incs/include.file') works fine locally but

include ('/incs/include.file') doesn't work, nor does ('proper/server/address/incs/include.file').

I've set Apache so that I can access the site locally as localhost:port/. I've got Alias to work so that a link with "/proper/server/address/" goes to the right place locally and gets served through localhost:port/.

I've added the localhost address to the include_path in php.ini, tried the physical hard drive address as well, tried just "/" as well...

I don't get an Apache Error, but get the php "failed opening" message.

I'm fast running out of ideas.... anybody else got any?

JK 2006-11-15 06:07 PM

Have you tried changing all slashes to backslashes?

('proper/server/address/incs/include.file')
('\proper\server\address\incs\include.file')

In php.ini, is the "include_path" line uncommented? Are you using the UNIX syntax (/path/etc) or the windows syntax (\path\etc)?

Jeremy 2006-11-15 06:28 PM

Changing the backslashes would break everything else under the localhost / apache & on the remote server :-( I'm really just trying to get a properly working local / apache version of the site so I can test mods to it in a 'live / real' environment and just upload it.

In php.ini, I'm using the Windows syntax. I wonder....... if Apache is doing calling on php if I should be using the Unix line and just referencing root?

JK 2006-11-15 06:40 PM

Not sure why it's not working, but I have a common 'includes' folder that I put in php.ini so i don't have to worry about paths in my scripts.

include_path = ".;\php;\www\includes;"

If you put your include dir in here, you should just be able to include('file.php'); and not worry about the slashes :)

Jeremy 2006-11-15 07:05 PM

that'd probably be waaaay easier...... but there's already xxK pages with /proper/server/address/ in the html :-(

LOL. It's driving me nuts, but as long as it works on the live box, I can kind of live with it :-)

cd34 2006-11-15 09:12 PM

windows apache always goes for a relative to the 'server'

what you might do is move your includes directory inside the webroot of the server, or, what some people do for cross development is do something like

define("PREFIX", "/whatever");

then do something like include PREFIX . "/inc/whatever";

not quite what you want, but it does almost the same thing.

oast 2006-11-20 04:14 PM

In the httpd.conf file, have you set the correct 'UserDir' to point to your Document Root?

I have a seperate partition for my mirrored web server (what is on the server is exactly what's on my home PC.

The line in the Apache httpd.conf file that sets this is:
UserDir "F:/home/username"

I also have VirtualHost definitions set up for each domain and a hosts file that makes my domains point to 127.0.0.1 when I turn the webserver on for local dev work.

atariFu 2006-11-21 12:17 PM

oast has a good idea about setting the UserDir.

It sounds like you have multiple files (possibly hundreds or more) that need to include this file.

What I would do is have a main include file that all scripts call regardless of what they are doing, this is handy for overriding anything at any point or passing variables between scripts.

In this global script just create a variable with your usual include file for the rest of your possibly hundreds of pages, eg:

$standard_include_path = "C:\apache\htdocs\blah\etc\";
?>

include("global_script.php");
include($standard_include_path);
?>

This way when you are working at home you only have to change your include path in one place and when you upload everything to the server just change it there too, or you might not even have to since you may not even need to edit the global script.

Also note how I addressed the include path: C:\apache etc..

I believe this is the right way to include files in windows if you want to start at the root.

If you want to edit in a real live environment though why not go get a junker pc, put linux on there and run it on your subnet, way easier. Windows has other incompatibilities that you may need to write hacks for in your code.


All times are GMT -4. The time now is 07:38 PM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc