I have main folder which includes images, css, index,header.php folders and files.
Now i created a new folder named forms in which a file form.php is created. Now what i did is included the header.php file from main folder. form.php calls the header.php but links like css/style.css
,javascripts/js.js
doesn't work inside the form.php. So give me a solution so that i can include header file in form.php as it is called in index.php.
First you define your Root folder or domain
Ex : define("ROOT","www.maysite.com/");
Then you add this code to your headr.php
<php
define("ROOT","www.maysite.com/");
?
<script type="text/javascript" src="<?php echo ROOT;?>javascript/js.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo ROOT;?>css/style.css" />
If these files are in your main folder, you can just include them using absolute paths, like this: /css/style.css
and /javascripts/js.js
You should try to have a sort of ROOT variable that holds an absolute path to the root of your website.
Every file will be able to use this variable no matter where they are in the directory structure as the path is absolute.
Lets assume that your root variable contains this value: /var/www/my_awesome_site/
,
Your index.php
file will reference files like this:
$root/css/style.css
And your form.php
would be able to use the same path:
$root/css/style.css