Jump to content



Photo

Define Constants For Site (Chpt 3, Pg 58)


  • Please log in to reply
6 replies to this topic

#1 Lynae

Lynae

    Newbie

  • Members
  • Pip
  • 15 posts

Posted 28 January 2012 - 12:28 PM

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,
Lynae
  • 0

#2 Edward

Edward

    Advanced Member

  • Members
  • PipPipPip
  • 817 posts

Posted 28 January 2012 - 2:12 PM

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

http://localhost/knowledge_is_power/www/index.php

And on the c drive it is located at

C:\xampp\htdocs\knowledge_is_power\www\index.php

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

#3 Edward

Edward

    Advanced Member

  • Members
  • PipPipPip
  • 817 posts

Posted 28 January 2012 - 2:22 PM

Also if your index.php file is in the htdocs directory then set BASE_URI to http://localhost/
  • 0

#4 Hermann

Hermann

    Member

  • Members
  • PipPip
  • 30 posts

Posted 28 January 2012 - 2:24 PM

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.
  • 2

#5 Lynae

Lynae

    Newbie

  • Members
  • Pip
  • 15 posts

Posted 28 January 2012 - 4:08 PM

Thanks Edward! That took care of my errors!
  • 1

#6 Edward

Edward

    Advanced Member

  • Members
  • PipPipPip
  • 817 posts

Posted 29 January 2012 - 1:08 PM

You are welcome.
  • 0

#7 Edward

Edward

    Advanced Member

  • Members
  • PipPipPip
  • 817 posts

Posted 1 February 2012 - 11:57 AM

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/');

  • 0