I am new to php and i am working on a project i am facing some problems with linking css and js files.
Now when the project is executed,First index.php loads (located in root directory) which includes home.php and everything in it is executed correctly.
But as soon as you click on ‘about’ link on the ‘home page’ ,the page is redirected to about.php( which is located inside Presentation/about.php )here the css and js linking fails…….
On execution of index.php it takes css link successfully (the link is as follows)
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
but later when the page is redirected to about.php it expects the link to be
<link href="../css/bootstrap-theme.min.css" rel="stylesheet">
and i am using a common file for these links, i kept all links in header.php(located in Presentation/Template/header.php)
I have also defined all paths in config.php(located in inc/config.php)
i have defined the path in config.php as follows
// SITE_ROOT contains the full path to the RichTongue folder define('SITE_ROOT', dirname(dirname(__FILE__))); // Application directories define('PRESENTATION_DIR', SITE_ROOT . '/Presentation/'); define('TEMPLATE_DIR', PRESENTATION_DIR.'Template/'); define('BUSINESS_DIR', SITE_ROOT . '/Business/'); define('CSS_DIR', SITE_ROOT. '/css/'); define('FONT_DIR', SITE_ROOT . '/fonts/'); define('IMAGE', SITE_ROOT . '/images/'); define('JS', SITE_ROOT . '/js/');
so i tried linking css in the following way
<link href="<?php echo CSS_DIR ?>bootstrap.min.css" rel="stylesheet" >
now the above code gives me an error in chrome which says
Not allowed to load local resource: file:///C:/xampp/htdocs/RichTongue/css/bootstrap.min.css
home.php:13
now the path in the error above(file:///C:/xampp/htdocs/RichTongue/css/bootstrap.min.css) is correct but it doesnt load the file and gives the error (error specified above)
Q)What should i do? what is the correct way of linking css and js files in php?
need help
Advertisement
Answer
set URl path for SITE_ROOT
if ur project path is C:/xampp/htdocs/RichTongue/css/bootstrap.min.css
so change with below line
define('SITE_ROOT', 'http://localhost/RichTongue');