Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
SlowJim

Ch3 - Creating Home Page - Config.inc.php Issue

Recommended Posts

I'm working through the Knowledge is Power tutorial. My document structure for this tutorial is based on mydomain.com/ee/pub/, where mysql.inc.php is located at mydomain.com/ee/mysql.inc.php and the home page is located at mydomain.com/ee/pub/index.php.

 

So in the config.inc.php file (which is inside /ee/pub/includes/) I've written definitions as such:

define("BASE_URI", "/ee/");
define("BASE_URL", "/ee/pub/");
define("MYSQL", BASE_URI . "mysql.inc.php");

When I test the home page when the section says to test it, I get a "failed to open stream" error about the line that says require(MYSQL), being equivalent to require("/ee/mysql.inc.php").

 

However the page works fine if I rewrite the one definition like so (and do nothing else):

define("MYSQL", "../mysql.inc.php");

But I can't think of any reason it won't work in the original way. Could someone shed some light on this? I'd rather have Larry Ullman's way working.

Share this post


Link to post
Share on other sites

Just like Larry said somewhere, that when you sleep on it. . .

 

I just found that if I define BASE_URI like

define("BASE_URI", "/home/my_server_dir/public_html/ee/");

then require(MYSQL); works for

define("MYSQL", BASE_URI . "mysql.inc.php");

Unfortunately, I'm still slightly confused why just "/ee/" doesn't work. In HTML, when linking a stylesheet for instance, you can href="/css/style.css" (using more creative names) and the base URL is assumed. I suppose PHP just goes by somewhat different rules in this regard. . . . Come to think of it, maybe that's just because it can make distinctions between URI and URL like a boss.

Share this post


Link to post
Share on other sites

The /ee/ doesn't work when referencing things because / means to start in the webroot directory. If I follow your paths right, the website is in /ee/pub, so any references to links and CSS and the like need to start with /ee/pub/

Share this post


Link to post
Share on other sites

That part I thought I had straight. For example (of why I thought I had that much straight), regardless of where an include of HTML might be located, whatever references the HTML makes need to be made as though they're being made from the file that does the including.

 

The problem I had was in making references in PHP and passively assuming that this is everywhere done the same way as it is done in HTML. For example, in HTML if I want to make reference to a JS file I can do so with the method of starting with /, with that symbol meaning the webroot directory in this context, but when I would make reference to a file in PHP (e.g., with an include statement, using defined constants) and if I assumed the initial / symbol meant the webroot, I got some kind of file not found error. In other words, by unthinkingly assuming that PHP referencing worked like HTML referencing in every way, I arrived at the problem I described above. While there's overlap between working PHP and HTML referencing (e.g., the ../ symbol works the same way in both), where the / symbol means the webroot in HTML, in PHP it means my home root on the server.

 

When you write for the first time, in Chapter 3, the statement

define ('BASE_URI', '/path/to/dir');

a negligent newcomer like me who didn't take your advice and study much PHP before coming to this book passively assumed that the initial / symbol meant exactly like does in HTML. Hence the problem I had. Then the following day, after some distance and rest, I followed that up with showing that I figured out what was wrong and trying to indicate the reason I made the error in the first place.

 

Now if I just completely misunderstood what you just said in your post, I'll just go slap myself with PHP and MySQL for Dynamic Web Sites 4e.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...