Jump to content
Larry Ullman's Book Forums

Define Constants For Site (Chpt 3, Pg 58)

Recommended Posts

I am unclear what I need to include for the first two constants on page 58, problem 3. Do I need to set the first constant up since my setup is according to figure 3-3?


The second and third constants are set up:


define ('BASE_URL','www.example.com/'); line 8

define ('MYSQL', BASE_URL . 'includes/mysql.inc.php');


Is this defining the URL of the website and do I also need to change this URL in my php.ini file? This part doesn't make sense to me since I am using http://localhost/



These are my errors:

An error occurred in script 'C:\xampp\htdocs\index.php' on line 8:

require(www.example.com/includes/mysql.inc.php) [function.require]: failed to open stream: No such file or directory

Fatal error: require() [function.require]: Failed opening required 'www.example.com/includes/mysql.inc.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\index.php on line 8


In my php.ini file under paths and directories, it has:


; Windows: "\path1;\path2"

include_path = ".;C:\xampp\php\PEAR"

Does this need to be changed to www.example.com or do I change my constants to this path?


Thank you,


Link to comment
Share on other sites

Assuming that your index.php file is in the htdocs folder, then try this


define ('BASE_URL', '/')


I have my site setup like this


define ('BASE_URI', 'http://localhost/knowledge_is_power/');
define ('BASE_URL', '/www/');
define ('PDFS_DIR', BASE_URI . '/pdfs/'); // Added in Chapter 5.
define ('MYSQL', '/includes/mysql.inc.php');


I am also using the xampp localhost for running the knowledge is power website, the location of my index.php file is here




And on the c drive it is located at




This should be enough info for you to figure it out if the above what i have written doesn't happen to work.

Link to comment
Share on other sites

I've struggled with this as well in the beginning. I've decided to leave it out of my code. Remember this book is only a guide and you should use whatever you're comfortable with. I've found that I'm more comfortable with $_SERVER['DOCUMENT_ROOT'], which equals for example www.myweb.com/ . Another piece of advice that I can give from my little experience, is to never forget the 'echo' command. It can tell you a lot. for example, if you want to know why your constants aren't working, display the value of it in the browser using echo and you'll solve this problem really quickly or at least that's how I learned how to use constants similar to the ones mentioned.

  • Upvote 2
Link to comment
Share on other sites

I would like to add a correction into this post i apologize for my silly mistake. The correct setting if you are using a localhost and you have placed your files in C:\xampp\htdocs\ should be:


define ('BASE_URI', 'C:\xampp\htdocs\');
define ('BASE_URL', 'http://localhost/');

Link to comment
Share on other sites

  • 1 year later...

Thanks again, Edward!  I've just spent a few million seconds rereading your comments, rechecking my stuff, slightly simplifying my file names, comparing, testing, scratching, etc., and finally have success with the KIP site.  What worked in the config.inc.php file is this:


// Determine location of files and the URL of the site:
define ('BASE_URI', 'C:/xampp/htdocs/_LUecommerce1/');
define ('BASE_URL', 'localhost/_LUecommerce1/html/');
define ('PDFS_DIR', BASE_URI . 'pdfs/'); // Added in Chapter 5.
define ('MYSQL', BASE_URI . 'mysql.inc.php');
It works in the Coffee one also (substituting "2" for "1") except that I haven't created and populated the db yet.  Will do it in the morning and am hopefully not overly confidently assuming it will come through with Larry's coffee sampler site!
Thx again, I really appreciate your help and encouragement to battle through it!
btw: how do you get those cute boxes in, with the colored text so nicely in place?
Link to comment
Share on other sites

Glad you managed to get it worked out. The cute boxes with colored text is a code box, you can add one to your post by clicking on the "<>" icon just below the smiley face icon.


Yes you will need to get some data into the database as some errors may be thrown if its trying to fetch something that is not there, that's unless you check for null values etc.

Link to comment
Share on other sites

Geoffrey, thanks for commenting.


I think the key to getting everything to work is to realize that your BASE_URL constant should be accessible from any web browser by starting the URL with http or https.


On the other hand, the BASE_URI constant should be defined as per the directory path to your server files on the actual web server.

In the case of a localhost on a Windows systems, this is likely akin to starting the path with "C:\", whereas on a Unix/Mac system, starting the path with "/".

  • Upvote 1
Link to comment
Share on other sites

Thx again, Edward, and HartleySan!  


I was premature in thinking the Coffee site would emerge in its full glory!  After setting up the db (carefully, after reading Larry's instructions after first trying without), the site "works" in that it comes up in browsers without error messages, but it's not displaying everything correctly. Here's what it looks like:


[NOTE: When trying to post this, later, I got a message, "trying to post more images than allowed" - so I've replaced some or all with text describing them.]


  • icon-home.gif -------------actually 4 of these, for index, cart, contact and sitemap
CoffeeWouldn't you love a cup right now?
  • Coffee ------------actually 5, for Coffee, Goodies, Sales, Wish List and Cart
Sale Items -------------actually 2 of them listed below this line Welcome to Our Online Coffee House!

We're so glad you made it. Have a seat. Let me get you a fresh, hot cup o' Joe. Cream and sugar? There you go.

Please use the links at the top to browse through our catalog. If you've been here before, you can find things you bookmarked by clicking on your Wish List and Cart links.

About Clever Coffee, Inc.

Clever Coffee, Inc. has been selling coffee online since 1923. For years, Clever Coffee, Inc. failed to make a profit, due to the lack of computers and the Internet. Yadda, yadda, yadda.

It's safe to shop here, promise!

© - Clever Coffee, Inc.
Site designed by: Templates.com
I guess it's not finding the various objects that are showing up here improperly (or improperly not showing up?).  In case it's my config.inc.php location settings, which are working fine like this for the ecommerce1 site, these are:
define ('BASE_URI', 'C:/xampp/htdocs/_LUecommerce2/');
define ('BASE_URL', 'localhost/_LUecommerce2/html/');
define ('MYSQL', BASE_URI . 'mysql.inc.php');
Again, I look forward to your helpful suggestions, with appreciation!


Link to comment
Share on other sites

It probably doesn't matter, but in Windows systems, you should use backslashes instead of forward slashes for paths. In other words, I'd change your BASE_URI string to the following:


Note that a second backslash is required in each instance to escape the first.


Beyond that, it's hard to help, as I can't honestly make sense of your post or what the problem is.

Would it be possible to put your site up on a public-facing server for us to see?


Link to comment
Share on other sites

Actually, you can use a single forward slash on Windows (which is unusual, but works), you just can't use a single back slash (which is  normal, but doesn't work).


The problem is that your site is in a subfolder: localhost/_LUecommerce2/html/, not just localhost. You've should have absolute references to the images, links, and CSS (which is required with the mod_rewrite), but your references probably don't start with /_LUecommerce2/html/.

Link to comment
Share on other sites



I understand that Windows allows either way, and indeed your suggestion made no difference, but thanks.  I had mentioned that that configuration worked fine for me with Larry Ullman's ecommerce1 site (Knowledge is Power).  Looking at your second point, I think that must be the explanation, and I'll dig into it.  Thanks!


Re. what it's all about: I'm simply trying to get Larry's e-commerce (per his Effortless E-Commerce book) working under xampp on my PC so that I can get to learn from them.  I have the Knowledge is Power site working fine, but t would be nice to have the Coffee site working as well, since it contains functions I need to acquire skills in.


My desire to learn this stuff is to use it on a website that I already have working (aquasilver.ca) but lacking e-commerce capabilities such as a decent, flexible shopping cart and Authorize.net e-payments (plus member log-in and possible also PayPal eventually).  I had PayPal working OK but found its shopping cart totally inadequate for my needs, then eventually discovered Larry's book, etc. and figured it would be my fastest route to doing what's needed (plus helping me get smart enough to do some other web projects I want to pursue).


I'm currently wrestling with the BIG question whether to (A) keep my existing aquasilver.ca site structure more or less as it is and somehow add Larry's techniques into it, or ('B') start fresh with a total copy of Larry's Coffee site in place of aquasilver.ca then somehow slide my aquasilver stuff into it, replacing the Coffee look and feel where applicable.  My existing site structure is VERY different from Larry's Coffee site so my head is spinning over this question.


My intuition tells me that the "B" option would be best, though I have nothing concrete to back that idea up!


Since I'm accustomed to working with Dreamweaver, I would be doing one or the other of these two options within an aquasilverTEST folder in c:/xampp/htdocs (as well as in my "local" folders on my D: drive, of course), side by side with my existing regular aquasilver folder in the same places.  I use NotePad++ also, as appropriate and convenient.


Any assistance towards resolving this question would be extremely welcome, since both these options look rather intimidating to me at the mo!  I'm sure there must be a wisdom-based choice better than what would happen if I tossed a coin to resolve it or just went on my intuition.



Link to comment
Share on other sites

Wow! Geez! Those are some tough questions.

I guess it really comes down to your motivation and time available.

If you have both, then I say go with B. I'd rethink the entire site, and implement something more chic and modern looking that better emphasizes good UX.


If you have neither, then I'd maybe just change the Orders page to be able to accept online orders as per the guidance offered in Larry's book.


It sounds to me like you're already leaning towards B, but you're hesitant to do so because it's a big undertaking with a lot of unknowns.


If I could offer maybe two pieces of advice:

1) I'd stop using Dreamweaver ASAP. The sooner you wean yourself off of that and use a regular text editor/IDE designed for programming, the better.

2) If all your customers are in America/Canada, you might want to consider Stripe for your payment method.


Please share your thoughts.

Link to comment
Share on other sites

HartleySan & Larry - with especial apologies to Larry!


I  think I jumbled your separate replies, attributing them both to HartleySan. Guess I shouldn't work so late!


Re. Larry's point: "The problem is that your site is in a subfolder: localhost/_LUecommerce2/html/, not just localhost. You've should have absolute references to the images, links, and CSS (which is required with the mod_rewrite), but your references probably don't start with /_LUecommerce2/html/."  If I understand that correctly, it means that I have either to put only my (aquasilver.ca) site files into xampp/htdocs/, hence being unable to use xampp for anything else, or to figure out how to fully qualify all the other stuff that needs qualifying, which I think is beyond me at this point.  I guess I could move the ecommerce sites elsewhere on my system to study, in conjunction with using the ecommerce websites at dmcinsights.com to see how the code actually works in practice.  That would be quite a workable solution but leaves me having to use xampp for only one test site (e.g. aquasilver.ca) at a time (acceptable I guess but not desired).  Did I get this right?


Re. Dreamweaver, I think I'm already weaning off it.  NotePad++ seems to work well, or would you suggest something else?


Re. aquasilver.ca, I agree it's not chic or modern.  I had trouble communicating with my wife who came up with the graphic parts!


Re. my choice of how to proceed with getting Larry's code working on it, I'll continue pondering the options a bit.


Re: using Stripe for the payment method, I actually got quite enthusiastic about it a few weeks ago and so I was excited to hear that you (Larry) are getting involved there.  Will you be coming up with tips on how to use it instead of PayPal and Authorize.net in your ecommerce sites?


Thanks again, and I greatly appreciate your kindness in helping people like me!

Link to comment
Share on other sites

You can definitely have as many sites as you want running from the htdocs folder by putting each site within its own folder. So long as all the paths match up, you're fine.

I would not recommend deleting everything else in the htdocs folder just to get one site running from the folder.


Notepad++ seems to be good for a lot of people, but my personal preference is Notepad2. It's a bit simpler than Notepad++, but it has everything I need and more.


Anyway, yeah, I agree that it would be a good idea to make sure you can get all the site functionality working before you switch everything over. As you suggested, I would test all the purchasing logic, and once you're sure that's working, I'd redesign the site as well as maybe move the existing info around to make it more accessible, and when all that's done and running on your local server, then I'd move everything over.


Best of luck.


As a final note, I don't want to put words in Larry's mouth, but I'm willing to bet that the 2nd edition of the e-commerce book will contain info about Stripe. I'm hoping that he adds a third sample site to the book that uses Stripe as the payment method.

Link to comment
Share on other sites

Yes, the second edition of the book will demonstrate Stripe, although it won't have a third example site. Rather than introduce a third example, I thought it'd be better to introduce a slew of ways that one can improve the first two examples. 

Link to comment
Share on other sites


  • Create New...