Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 2006-11-15, 05:30 PM   #1
Jeremy
Remember to rebel against the authorities, kids!
 
Jeremy's Avatar
 
Join Date: Aug 2003
Location: AU
Posts: 406
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?
__________________
XXX Porno Hardcore
Jeremy is offline   Reply With Quote
Old 2006-11-15, 06:07 PM   #2
JK
Well you know boys, a nuclear reactor is a lot like women. You just have to read the manual and press the right button
 
Join Date: Nov 2003
Posts: 157
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)?
__________________
To alcohol! The cause of, and solution to, all of life’s problems
JK is offline   Reply With Quote
Old 2006-11-15, 06:28 PM   #3
Jeremy
Remember to rebel against the authorities, kids!
 
Jeremy's Avatar
 
Join Date: Aug 2003
Location: AU
Posts: 406
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?
__________________
XXX Porno Hardcore
Jeremy is offline   Reply With Quote
Old 2006-11-15, 06:40 PM   #4
JK
Well you know boys, a nuclear reactor is a lot like women. You just have to read the manual and press the right button
 
Join Date: Nov 2003
Posts: 157
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
__________________
To alcohol! The cause of, and solution to, all of life’s problems
JK is offline   Reply With Quote
Old 2006-11-15, 07:05 PM   #5
Jeremy
Remember to rebel against the authorities, kids!
 
Jeremy's Avatar
 
Join Date: Aug 2003
Location: AU
Posts: 406
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 :-)
__________________
XXX Porno Hardcore
Jeremy is offline   Reply With Quote
Old 2006-11-15, 09:12 PM   #6
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
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.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
Old 2006-11-20, 04:14 PM   #7
oast
With $10,000, we'd be millionaires! We could buy all kinds of useful things like ... love!
 
oast's Avatar
 
Join Date: May 2004
Location: UK
Posts: 316
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.
__________________
Playboy Webmasters - The name says it all! $35 per signup or 60% revshare.
oast is offline   Reply With Quote
Old 2006-11-21, 12:17 PM   #8
atariFu
Aw, Dad, you've done a lot of great things, but you're a very old man, and old people are useless
 
Join Date: Aug 2005
Posts: 25
Send a message via ICQ to atariFu
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:

<? // global php script
$standard_include_path = "C:\apache\htdocs\blah\etc\";
?>

<? // other page
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.
__________________
Atari
www.turbothumbz.com
Porn Search Engine [-_\]

Last edited by atariFu; 2006-11-21 at 12:20 PM..
atariFu is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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