Windows 7 and wamp
Windows 7 and wamp
If you want to side-step .htaccess altogether, you *could* set a global path variable in a common file.
I do something similar to you (each website in a sub-folder) but in my main header.php file for each website ,I include a $myRoot variable - something like;And then prefix the paths in my HTML markup with the variable, like this (all of my website pages are .php so this works for me);Code:<?php $myRoot = 'http://localhost/mywebsite/'; ?>The output will be:Code:<script src="<?php echo $myRoot;?>scripts/general.js"></script><script src="http://localhost/mywebsite/scripts/general.js"></script>
Then when you move your website to the live server, you only change your $myRoot variable in the common file and the change filters down to all the paths in your markup;OR just;Code:<?php $myRoot = 'http://www.mywebsite.com/'; ?>so the output would be;Code:<?php $myRoot = '/'; ?><script src="http://www.mywebsite.com/scripts/general.js"></script>
or<script src="/scripts/general.js"></script>
You wouldn't be able to do this in all cases but it *might* work for you.
Focus on Function Web Design
Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps
I have thought of your concept to Bev. Am I correct when saying that the / does not work as expected for php with include() and require(), I seem to get a fatal error when using it on a live site. Does php look from the root already or what?
Yes, if you use "/" in a php include() its trying to look from a place even deeper than the root of your wamp-dwelling website - ie. the root of your C drive instead.
But, you can create a variable for your php includes using the same idea though;
There are other ways to define a root but this is the one I use (old habits and all)Code:$myRootURL = 'http://localhost/mywebsite/'; $myRootPATH = 'C:\wamp\www\mywebsite\';
EDIT: some other ways to define a root path for php includes: http://stackoverflow.com/questions/3...de-path-in-php
Last edited by Beverleyh; 07-01-2013 at 05:15 PM. Reason: More ways to define root
Focus on Function Web Design
Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps
That's a great solution and totally workable/sufficient in many cases. I'd only suggest using constants instead of variables, so you can't accidentally modify/overwrite them (and they will always be available globally, regardless of scope):You could even do some switching logic so you wouldn't need to change them all manually when you uploaded to your server:PHP Code:
<?php
define( 'ROOT_URL','/localhost/sites/example' );
define( 'ROOT_PATH','C:\wamp\www\sites\example' );PHP Code:
<?php
if( $_SERVER['SERVER_NAME'] === 'localhost' ){
require file/that/defines/local/constants.php;
}
else{
require file/that/defines/production/constants.php;
}
Nice - I'll have to remember that switcharoo logic traq![]()
Focus on Function Web Design
Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps
Thanks for all the input. I have taken the time and converted my cms to use / on most links and image paths. It wasn't that terrible to do really. I made a few define() to help, although a couple of these I already had but mostly for localhost use. I have a few different versions so that I have options of when and where I need to use them depending on localhost or online and php includes or html links.
PHP Code:
// Strips the SERVER HOST to main domain name
function stripHost()
{
if(substr($_SERVER['HTTP_HOST'], 0, 4) == "www.")
{$server = substr($_SERVER['HTTP_HOST'], 4);}
else {$server = $_SERVER['HTTP_HOST'];}
return $server;
}
define("SITE_SERVER", $site_server = stripHost());
define("CURRENT_DIR", (dirname($_SERVER['PHP_SELF']) == '/') ? '/' : dirname($_SERVER['PHP_SELF']).'/');
define("BASE_URL", (SITE_SERVER == 'localhost') ? 'http://'.SITE_SERVER.CURRENT_DIR : '/');
define("ROOT", dirname(dirname(__FILE__)).'/');
I also just figured out how to setup virtual host on my localhost, so that's really cool!
You never know everything, I learn everyday!
Bookmarks