
Originally Posted by
vinpkl
hi all
i have a comman variable on top of every page
PHP Code:
$domain = "http://localhost/myfolder";
and i m writing addresses of css files and images as
PHP Code:
<link rel="stylesheet" type="text/css" href="<? echo $domain ?>/styles.css" />
But how would i call
$domain variable in my stylesheet
Code:
body{font-size:12px; background:url(../images/bg.gif) repeat-x;}
vineet
Couple of points maybe worth noting:
I am curious to know why you want a $domain variable at the top of every page?
I envisage "file not found " problems will arise when the files are uploaded to www.your-online-site.com.
The way I get round this is to test and see if platform is localhost and to define relevant constants.
// Typical file
PHP Code:
<?php
// $domain = "http://localhost/myfolder";
require '/your-include-path/constants.php'
<link rel="stylesheet" type="text/css" href="<?php echo DOMAIN ?>/styles.css" />
// constants.php
PHP Code:
<?
defined('LOCALHOST') ?: define('localhost', 'localhost' == $_SERVER['SERVER_NAME']);
if (LOCALHOST)
{
defined('DOMAIN') ?: define('DOMAIN', 'http://localhost/');
defined('P_IMGS') ?: define('P_IMGS', 'http://localhost/path-to-images/');
}
else
{
defined('DOMAIN') ?: define('DOMAIN', 'http://your-online-site.com/');
defined('P_IMGS') ?: define('P_IMGS', 'http://your-online-site.com/path-to-images/');
}
<hr />
But a far easier solution is to create a localhost/assets-folder/ which is duplicated online. This method does not require any constants or variables...
Test the following code to ensure that PHP prepends the URL on both localhost and online platforms.
# typical files
PHP Code:
<?php
<link rel="stylesheet" type="text/css" href="/assets-folder/css/styles.css" />
// stylesheet
body{font-size:12px; background:url( /assets-folder/images/bg.gif ) repeat-x;}
Bookmarks