nomadsoul Posted June 25, 2011 Share Posted June 25, 2011 Hi all, would a relative or absolute path be better for security within the BASE_URI definition? (/coffee is my base folder) And the book says that I should put mysql.inc.php connection script outside the web root folder. So am I using the dot and slash correctly below (./mysql.inc.php) ? define ('BASE_URI', 'http://www.mysite.com/coffee'); define ('BASE_URL', 'localhost:8888/'); define ('MYSQL', BASE_URI . './mysql.inc.php'); Another question: I'm curious of why the use of port 8888 Link to comment Share on other sites More sharing options...
HartleySan Posted June 25, 2011 Share Posted June 25, 2011 The base URI is the path from the very base of, for example, your hosting site's server to your site. If the server your hosting from is a UNIX/Linux machine, the path will probably be something like '/home/domain-name/'. From there, you might want to add 'public_html' to the base URI for files that are in the web root, and then just the file name for files outside the web root. Basically, there are a lot of possibilities. Here's an example though: Let's imagine that your domain name is example.com. If that were the case, then you might define the following base URI: define('BASE_URI','/home/example/'); And the link to your MySQL connect file would be the following: define('MYSQL',BASE_URI . 'mysqli_connect.php'); And the base folder for the coffee site, which is in the web root could be either of the following: define('BASE_COFFEE_URL',BASE_URI . 'public_html/coffee/'); define('BASE_COFFEE_URL','http://www.example.com/coffee/'); Anyway, just some ideas. 1 Link to comment Share on other sites More sharing options...
nomadsoul Posted June 25, 2011 Author Share Posted June 25, 2011 The base URI is the path from the very base of, for example, your hosting site's server to your site. If the server your hosting from is a UNIX/Linux machine, the path will probably be something like '/home/domain-name/'. From there, you might want to add 'public_html' to the base URI for files that are in the web root, and then just the file name for files outside the web root. Basically, there are a lot of possibilities. Here's an example though: Let's imagine that your domain name is example.com. If that were the case, then you might define the following base URI: define('BASE_URI','/home/example/'); And the link to your MySQL connect file would be the following: define('MYSQL',BASE_URI . 'mysqli_connect.php'); And the base folder for the coffee site, which is in the web root could be either of the following: define('BASE_COFFEE_URL',BASE_URI . 'public_html/coffee/'); define('BASE_COFFEE_URL','http://www.example.com/coffee/'); Anyway, just some ideas. Thanks, that clears it up quite a bit. My Linux host does have the public_html directory with all my coffee files and so does the www folder with the shortcut icon on it. I forgot the term in Unix when they do this. "Basically, there are a lot of possibilities." -seems to be. And can be a bit confusing in the Linux world. Link to comment Share on other sites More sharing options...
HartleySan Posted June 25, 2011 Share Posted June 25, 2011 If you're used to Windows, then yeah, it can be confusing. But once you get used to UNIX, you realize it's actually a lot more logical than Windows, and Microsoft really seemed to go out of their way to make things annoying. Link to comment Share on other sites More sharing options...
Matt Posted August 15, 2011 Share Posted August 15, 2011 Well, here we go with the absolute path errors again! In my file I'm trying to include the following file: include ('http://' . BASE_URL . 'includes/gallery_login.inc.php'); Here is my BASE_URL definition in config file: define ('BASE_URL', 'www.tuesdaygirl.org/'); Which a third grader could tell you should result in this: http://www.tuesdaygirl.org/includes/gallery_login.inc.php However, once again, error, after error, after error!!! An error occurred in script '/var/www/html/includes/show_school.inc.php' on line 37: include() [function.include]: URL file-access is disabled in the server configuration Array This makes absolutely no sense! I gave up doing this a while ago because of the same errors, however, I thought I'd give it another try. Unless anyone has any ideas for why this ALWAYS generates errors, I guess it's back to '../../includes/etc..." Thanks, Matt - Larry, the "absolute" vs. "relative" path topic (and the many mind bending frustrations that go along with it) has come up time and time again in this forum! I feel that it really needs a thorough going over in the next edition of one of your PHP books! Link to comment Share on other sites More sharing options...
Larry Posted August 15, 2011 Share Posted August 15, 2011 This particular problem has nothing to do with absolute and relative paths but is actually caused by the fact that you're trying to include something in PHP via http. Use HTTP for Web stuff, use the file system for PHP includes. And I'm actually recording a screencast now, to be published as part of the PHP and MySQL book, that explains absolute and relative paths in detail. Link to comment Share on other sites More sharing options...
Matt Posted August 15, 2011 Share Posted August 15, 2011 Use HTTP for Web stuff, use the file system for PHP includes. So I should be using the BASE_URI then? And I'm actually recording a screencast now, to be published as part of the PHP and MySQL book, that explains absolute and relative paths in detail. Thanks a lot for that Larry! Very much appreciated! Matt Link to comment Share on other sites More sharing options...
Larry Posted August 15, 2011 Share Posted August 15, 2011 So I should be using the BASE_URI then? Yes, exactly, although you'll also have to drop the use of 'HTTP://'. As a rule of thumb, including or generally dealing with files on the server in PHP should be done via the filesystem. Including or referencing files and folders on the server using HTML, CSS, and JavaScript should be done using HTTP (implicitly or overtly). Link to comment Share on other sites More sharing options...
Matt Posted August 17, 2011 Share Posted August 17, 2011 As a rule of thumb, including or generally dealing with files on the server in PHP should be done via the filesystem. Including or referencing files and folders on the server using HTML, CSS, and JavaScript should be done using HTTP (implicitly or overtly). Larry, I didn't know that, but it makes sense! Thanks for the clarification! Matt Link to comment Share on other sites More sharing options...
Recommended Posts