krazyk Posted May 14, 2012 Share Posted May 14, 2012 hello , i have created web application in which i have divided the all parts of page like - main header part - contains the <!DOCTYPE to <body> part other header part - contains the logo,slideshow of the header of page then the main part and at the end footer part i have created on folder which contains the detail of page content info referenced from the other pages from main content.. here i am facing problem as the style sheet , javascripts and the other header part of file is not references well.. how to do it? plz guide me with correct solution awaiting for better response... Quote Link to comment https://forums.phpfreaks.com/topic/262496-include-files-in-other-php-pages/ Share on other sites More sharing options...
The Letter E Posted May 14, 2012 Share Posted May 14, 2012 hello , i have created web application in which i have divided the all parts of page like - main header part - contains the <!DOCTYPE to <body> part other header part - contains the logo,slideshow of the header of page then the main part and at the end footer part i have created on folder which contains the detail of page content info referenced from the other pages from main content.. here i am facing problem as the style sheet , javascripts and the other header part of file is not references well.. how to do it? please guide me with correct solution awaiting for better response... main header - header.php You want to include your js and css files in your header, I'll give one example of each <!doctype HTML> <html> <head> <title>PAGE TITLE</title> <!-- CSS INCLUDE --> <link rel="stylesheet" type="text/css" href="path/to/style.css" /> <!-- JS INCLUDE --> <script type="text/javascript" src="path/to/script.js"></script> //etc... other header - sub_header.php //your code here.... footer - footer.php //footer code here </body> </html> main page - index.php <?php include('path/to/header.php'); include('path/to/sub_header.php'); ?> <!-- WRITE THE HTML FOR THIS PAGE HERE --> <?php //YOU CAN BUST OUT SOME PHP TAGS AGAIN IF YOU WANT?> <?=$or_short_tags?><!-- TO ECHO A VARIABLE --> <? //do some short procedures here ?> <?php include('path/to/footer.php'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/262496-include-files-in-other-php-pages/#findComment-1345251 Share on other sites More sharing options...
krazyk Posted May 14, 2012 Author Share Posted May 14, 2012 thanks for the reply .. i have done the same thing ... but the problem is that for example in index.php thr is one link to go inner section (like index_detail.php which is in for example details folder) when i click the link to get index_detail.php page to be viewed ... it shows the page bt without css and javascript references !!! whr i am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/262496-include-files-in-other-php-pages/#findComment-1345255 Share on other sites More sharing options...
Lambneck Posted May 14, 2012 Share Posted May 14, 2012 Did you double-check to see if the paths were correct? If you are opening a file that is in a directory that doesnt have your css within it then you will need to add to go up a directory by prefixing your path with "../" Quote Link to comment https://forums.phpfreaks.com/topic/262496-include-files-in-other-php-pages/#findComment-1345266 Share on other sites More sharing options...
krazyk Posted May 14, 2012 Author Share Posted May 14, 2012 well i have my css file reference into header.php which is not in my directory and i am accessing that header.php file into the files which are in directory by giving path as ../ do i also need that header.php file into the directory to access? or the reference is not working properly...!!! Quote Link to comment https://forums.phpfreaks.com/topic/262496-include-files-in-other-php-pages/#findComment-1345305 Share on other sites More sharing options...
cpd Posted May 14, 2012 Share Posted May 14, 2012 Explaining files within files from left to right, north to south is difficult. Your better off giving us an example of your code. We can better assist with something to look at. Quote Link to comment https://forums.phpfreaks.com/topic/262496-include-files-in-other-php-pages/#findComment-1345310 Share on other sites More sharing options...
krazyk Posted May 14, 2012 Author Share Posted May 14, 2012 yes u r true ... thanx for reply.... its better to show the code here is my code ... index.php <?php $page_title = 'welcome page'; include('main-header.php'); ?> <form id="frmhome" name="frmhome" action=""> <?php $page='home'; include('header.php'); ?> <span id="span-head">Welcome!<br /> </span> <div class="divcontent"> welcome ...!!! <a href="details/detail.php">click here to read more</a> </div> <?php include('rightpane.php'); include('footer.tpl'); ?> here is my main-header.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo $page_title; ?></title> <link rel="stylesheet" href="style/master.css" type="text/css" /> <script type="text/javascript" src="jscript/jquey.min.js"></script> <script type="text/javascript" src="jscript/DynamicNavigation.js"></script> <script type="text/javascript" src="jscript/scripts.js"></script> </head> <body> here is header.php <!-- background-image --> <div class="ImageDiv"> <img src="images/home-page/home-background/imgbg.jpg" alt="lemon" height="100%" width="100%" /> </div> <div id="Mainwrapper"> <div id="wrapper"> <!-- start of header --> <div id="header"> <a href="index.php"><img src="images/home-page/Logo.png" alt="logo" /></a> </div> <!-- end of header--> <!-- start of menu --> <div id="nav-links"> <ul class="menu"> <?php if($page == 'home') { ?> <li class="active"><a href="index.php" title="Home"><span>Home</span></a></li> <?php } else { ?> <li><a href="index.php" title="Home"><span>Home</span></a></li> <?php } if($page == 'about-us') { ?> <li class="active"><a href="about-us.php" title="About Us"><span>About Us</span></a></li> <?php } else { ?> <li><a href="about-us.php" title="About Us"><span>About Us</span></a></li> <?php } if($page == 'contact-us') { ?> <li class="active"><a href="contact-us.php" title="Contact Us"><span>Contact Us</span></a></li> <?php } else { ?> <li><a href="contact-us.php" title="Contact Us"><span>Contact Us</span></a></li> <?php }?> </ul> </div> <!-- end of menu--> <!-- start of slider --> <div id='slider'> <a href="#"> <img src="images/home-page/slider-images/img1.jpg"> </a> <a href="#"> <img src="images/home-page/slider-images/img2.JPG"> </a> <a href="#"> <img src="images/home-page/slider-images/img3.jpg"> </a> </div> <!-- end of slider --> <!----------- start of main content --------------------> <div id="content"> i have one folder as details which is having detail page of other page... when i click the link of index.php it opens the details.php here is details.php <?php $page_title = 'Xplore Travel Services'; include('../main-header.php'); ?> <form id="frmdetails" name="frmdetails" action=""> <?php $page = 'details'; include ('../header.php'); ?> <span id="span-head">details<br /> </span> <div class="divcontent"> detailsss.... </div> </form> <?php include('../rightpane.php'); include('../footer.tpl'); ?> well i have given the link as ../ into the details.php bt no result becoz it is in the folder do i need to place the all header,footer files into this folder also? plz give me the solution... thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/262496-include-files-in-other-php-pages/#findComment-1345377 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.