Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 24th, 2004, 07:01 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP Include_path

Hey all
I recently got some webspace. It's on a Windows() server.
On the other free web space I used a .htaccess file to define
the include paths. However it is not working on the new space
since windows doesn't recognise .htaccess.
So the question are:
1) how do you define include paths on a windows server?
2) should I get my host to move me to linux servers?

Cheers

Reply With Quote
  #2 (permalink)  
Old November 24th, 2004, 07:28 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;how do you define include paths on a windows server
ASP on windows:

PHP on windows:
include('path/fileName.php);

NOTE: I no longer use .inc for include filed for security reasons, including a .asp or a .php works the same. Throw the path to a .inc file in the address bar to see why, it appears in the browser as it does in your code editor.

;;;should I get my host to move me to linux servers
I would, although I have been told recently on this forum PHP pages run fine on a windows box. This I did know but its not a simple as ABC...

Wind is your friend
Matt
Reply With Quote
  #3 (permalink)  
Old November 24th, 2004, 08:12 PM
Friend of Wrox
 
Join Date: Nov 2003
Location: , , .
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

The PHP version of include looks like this:

include "filename.php";

I would move to a Linux box because they're usually cheaper than Windows... unless you've found some deal where you get ASP support for the same price as PHP support. Also, they recognize .htaccess, etc. which can be pretty helpful.

And yes, PHP runs fine on Windows. I'd think it'd be slower, but it's really about the same speed (in my experience). I used a PHP/IIS/WindowsXP installer from PHP.net (really easy to install) and so far I've had no problems.

Now, MySQL on Windows.... that's different ;)

HTH!

-Snib
Where will you be in 100 years?
Try new FreshView 0.2!
Reply With Quote
  #4 (permalink)  
Old November 24th, 2004, 08:18 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

In my experience Windows-based serving is slower. A co-worker of mine installed Apache / PHP / MySQL on a Windows server and complained about how much slower it was than Fedora Core 2. Needless to say, he ended up sticking with Linux. I don't know how much truth there is to it, cause I never timed the execution personally. You can look at the PHP function microtime for an example of how to time the execution of a PHP script to run some experiments for yourself.

http://www.php.net/microtime

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote
  #5 (permalink)  
Old November 24th, 2004, 08:26 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

rugalb
Sorry for the in correct include syntax at first, instead of editing my original post I should have created a new one.

BTW:
MySql on windows. I use SQLYog, wow what a tool - check out:

http://www.webyog.com/sqlyog/index.php

IMO massively better than PHP myAdmin, they have a page dedicated to comparing the two. I had to learn PHP a while back now, PHPmyAdmin was a problem for me, SQLYog smoothed this over and removed most of the frustration.


Wind is your friend
Matt
Reply With Quote
  #6 (permalink)  
Old November 24th, 2004, 09:56 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by mat41
 ;;;how do you define include paths on a windows server
ASP on windows:

PHP on windows:
include('path/fileName.php);
I know how to do include statements. What I'm asking is, is there a way to define the path. My site has many directory levels, so for example:
root/
root/news
root/features
root/news/2004

If I have a template as so: root/inc/template.htm

and I use an include: include("inc/template.htm");

From the root it is found ok. From the subfolders it isn't.
On linux servers you can define it in the .htaccess with the
following:
php_value include_path ".:../:./inc":../inc"

How do you define a universal default path on a windows server?


Reply With Quote
  #7 (permalink)  
Old November 24th, 2004, 10:20 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;How do you define a universal default path on a windows server?
Not sure, I can tell you how to define a path to a desired location from a pysical location. Using ../ will take you back up a level and ../../ takes you up two levels etc

If I have a dir structure like:

root/inc
root/news/2004

And I want to place an include to a file inside the inc dir from a file in the 2004 dir, I would:
include("../inc/filename.php");

Wind is your friend
Matt
Reply With Quote
  #8 (permalink)  
Old November 25th, 2004, 09:11 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well I guess you're on IIs right?

This directive can be set for Windows too.
php_value include_path ".:../:./inc":../inc"

Except you use a semi colon instead of a colon to separate paths.

So the question comes down to setting directives, you don't have access to php.ini and IIs doesn't have anything similar to .htaccess (at least as far as I know). This is another reason I like Apache!

You can set the include_path directive at run time too with the ini_set function.

ini_set('include_path', '.;C:/Windows Path/1;F:/www/');

Of course that isn't nearly as useful and if your files are all spread out will be frustrating to implement.

Personally to avoid things like this I tend to chose absolute paths.

if (!isset($_SERVER['DOCUMENT_ROOT']))
{
    $_SERVER['DOCUMENT_ROOT'] = ''; // Manually define the path to the www root dir.
}

define('ABSOLUTE_PATH', $_SERVER['DOCUMENT_ROOT']);

include ABSOLUTE_PATH.'/includes/classes/library.class.php';

With this you have but one line to change if moving to a new server or shuffling files to a new directory (considering you have a reusable library and templating system). And even that one line is uneccessary should the $_SERVER['DOCUMENT_ROOT'] variable already be defined for you (don't think IIs provides that variable, Apache does).

You also avoid the circus of relative paths with this approach. Relative paths are fine and dandy till you want to include a script in a sub directory (which contains relative paths) in a script in a different directory, which causes the relative paths to not resolve.

Same thing for any HTML being output. Better to use an absolute path like '/images/file.jpg' as opposed to 'images/file.jpg', the latter won't be found if you decide that you need to include that script in a script in a different directory.

HTH!

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote
  #9 (permalink)  
Old November 25th, 2004, 11:47 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by richard.york
Of course that isn't nearly as useful and if your files are all spread out will be frustrating to implement.

Personally to avoid things like this I tend to chose absolute paths.

if (!isset($_SERVER['DOCUMENT_ROOT']))
{
    $_SERVER['DOCUMENT_ROOT'] = ''; // Manually define the path to the www root dir.
}

define('ABSOLUTE_PATH', $_SERVER['DOCUMENT_ROOT']);

include ABSOLUTE_PATH.'/includes/classes/library.class.php';

With this you have but one line to change if moving to a new server or shuffling files to a new directory (considering you have a reusable library and templating system).
I'm a bit confused here. I tried the first bit on a page, and it duly created the document_server. However it only did it for that instance of the page. If I load another page it loses the info. Thus this would need to be inserted into every page, an inpractical solution. Is there a way to make the definition of document_server persistent? Isn't it possible to predefine the ini_set command so that the "include_path" is predefined for the site?

Unfortunately it turns out the linux space isn't open to me. I have ot stick with the windows IIS server So I have to do something like this. Using ini_set works, but I'd have to do it in every page. I also can do php include "http://mysite.com/inc/template.htm", but again I'd have to edit every page. It's not what I want to do but I may have to.
Reply With Quote
  #10 (permalink)  
Old November 26th, 2004, 09:04 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

> Isn't it possible to predefine the ini_set command so that the "include_path" is predefined
> for the site?

Not without access to the php.ini configuration file. If you used Apache vs. IIs you could use .htaccess to set PHP directives on a per directory basis. The ini_set() function only sets directives at run time for the currently executing script. The only way to get around this is to either build a templating system, where common functions and objects are all included in a single file and then that file is included in all of the scripts for a site, or switch to Apache.

Regards,
Rich

--
[http://www.smilingsouls.net]
Mail_IMAP: A PHP/C-Client/PEAR solution for webmail
Author: Beginning CSS: Cascading Style Sheets For Web Design
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beg. PHP 5 > Ch. 11 - fetch_field.php crater BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 January 2nd, 2007 12:20 PM
how do we change include_path nidhimittal PHP How-To 0 June 29th, 2006 04:13 AM
begin php & mysql - chapter 12, user_form.php jon_stubber Beginning PHP 1 March 9th, 2006 10:57 AM
Error: movie.php & commit.php on p182-186, ch6 willburke BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 October 12th, 2004 02:48 PM
php.ini include_path error problem paddy PHP How-To 1 July 21st, 2003 03:09 PM



All times are GMT -4. The time now is 10:18 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.