PHP's include function ???

Reply

Join Date: Jan 2006
Posts: 89
Reputation: j4mes_bond25 is an unknown quantity at this point 
Solved Threads: 0
j4mes_bond25's Avatar
j4mes_bond25 j4mes_bond25 is offline Offline
Junior Poster in Training

PHP's include function ???

 
0
  #1
May 18th, 2006
After exploring PHP for the past few days, I've been trying to use it on the new CSS based website that I'm creating.

I'm trying to use "include" function in order to get my "header", "topMenu", "leftMenu", "rightMenu" and "bottomMenu", since in ALL the pages, these would be common. The only difference in different pages would be the "contentArea". Every single page is linked with an CSS stylesheet.

I'm trying to achive it using the tutorial on this website:

http://www.tizag.com/phpT/include.php

As said in the website's tutorial, I've created "menu.inc" file with contents linked with the stylesheet:

Menu.inc codes are:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  5. <title>Alcohol - Main Page</title>
  6. <link rel="stylesheet" type="text/css" href="style.css"/>
  7. </head>
  8.  
  9. <body>
  10. <div id="header">
  11. <p>Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header.</p>
  12. </div>
  13.  
  14. <div id="topMenu">
  15. <p>Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. </p>
  16. </div>
  17.  
  18. <div id="leftContent">
  19. <p>Left Menu.</p>
  20. <p>Left Menu.</p>
  21. <p>Left Menu.</p>
  22. <p>Left Menu.</p>
  23. <p>Left Menu.</p>
  24. <p>Left Menu.</p>
  25. <p>Left Menu.</p>
  26. <p>Left Menu.</p>
  27. <p>Left Menu.</p>
  28. <p>Left Menu.</p>
  29. <p>Left Menu.</p>
  30. <p>Left Menu.</p>
  31. <p>Left Menu.</p>
  32. </div>
  33.  
  34. <div id="rightContent">
  35. <p>Right Menu.</p>
  36. <p>Right Menu.</p>
  37. <p>Right Menu.</p>
  38. <p>Right Menu.</p>
  39. <p>Right Menu.</p>
  40. <p>Right Menu.</p>
  41. <p>Right Menu.</p>
  42. <p>Right Menu.</p>
  43. <p>Right Menu.</p>
  44. <p>Right Menu.</p>
  45. <p>Right Menu.</p>
  46. <p>Right Menu.</p>
  47. <p>Right Menu.</p>
  48. </div>
  49.  
  50. <div id="centerContent">
  51. <p class="first-letter">Following are the websites that I stumbled upon and enlightened myself with various different CSS based things at different stages of the site development. These are the list of ONLY the website which I used for designing this website and not the contents within the website itself.</p>
  52.  
  53. <p>Following are the websites that I stumbled upon and enlightened myself with various different CSS based things at different stages of the site development. These are the list of ONLY the website which I used for designing this website and not the contents within the website itself.</p>
  54.  
  55. <p>Following are the websites that I stumbled upon and enlightened myself with various different CSS based things at different stages of the site development. These are the list of ONLY the website which I used for designing this website and not the contents within the website itself.</p>
  56.  
  57. <p>Following are the websites that I stumbled upon and enlightened myself with various different CSS based things at different stages of the site development. These are the list of ONLY the website which I used for designing this website and not the contents within the website itself.</p>
  58.  
  59. <p>Additionally, I'll be working on the accessibility issue of this website making it possible for viewers to see the website choosing different font size, text colour and background colour.</p>
  60.  
  61. </div>
  62.  
  63. <div id="footer">
  64. Last Updated:
  65. <script type="text/javascript">
  66.  
  67. <!-- Begin
  68. var days = new Array(8);
  69. days[1] = "Sunday";
  70. days[2] = "Monday";
  71. days[3] = "Tuesday";
  72. days[4] = "Wednesday";
  73. days[5] = "Thursday";
  74. days[6] = "Friday";
  75. days[7] = "Saturday";
  76.  
  77. var months = new Array(13);
  78. months[1] = "January";
  79. months[2] = "February";
  80. months[3] = "March";
  81. months[4] = "April";
  82. months[5] = "May";
  83. months[6] = "June";
  84. months[7] = "July";
  85. months[8] = "August";
  86. months[9] = "September";
  87. months[10] = "October";
  88. months[11] = "November";
  89. months[12] = "December";
  90.  
  91. var dateObj = new Date(document.lastModified)
  92. var wday = days[dateObj.getDay() + 1]
  93. var lmonth = months[dateObj.getMonth() + 1]
  94. var date = dateObj.getDate()
  95. var fyear = dateObj.getYear()
  96. if (fyear < 2000)
  97. fyear = fyear + 1900
  98. document.write(wday + ", " + lmonth + " " + date + ", " + fyear)
  99. // End -->
  100. </script>
  101. </div>
  102.  
  103.  
  104.  
  105. </body>
  106. </html>
  107.  

About.php is the page that I've linked "menu.inc". It's code include:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
  5. <title>Alcohol - Main Page</title>
  6. <link rel="stylesheet" type="text/css" href="style.css"/>
  7. </head>
  8.  
  9. <body>
  10. <?php include("menu.inc");?>
  11.  
  12. </body>
  13. </html>

Now, if I try to visit about.php on my browser, with the hope of seeing the page (as attached, which is "about.html"), I get the error message saying:

Invalid Menu Handle

I've kept my Apache open as well. Am I doing something silly ???

.................................................................................................

Just in case, someone wish to see the stylesheet itself:

  1. /* CSS Document */
  2.  
  3. body
  4. {
  5. background-color:black;
  6. background-attachment:fixed;
  7. }
  8.  
  9. /* ........................................ HEADER ........................................ */
  10.  
  11. #header
  12. {
  13. width:100%;
  14. border:1px solid red;
  15. text-align:center;
  16. background-color:blue;
  17. }
  18.  
  19.  
  20. /* ......................................... TOP MENU .................................... */
  21.  
  22. #topMenu
  23. {
  24. width:100%;
  25. float:right;
  26. background-color:red;
  27. border:1px solid red;
  28. }
  29.  
  30.  
  31. /* ................................... CONTENT ................................................ */
  32.  
  33. #leftContent
  34. {
  35. float:left;
  36. width:10%;
  37. border:1px solid red;
  38. background-color:green;
  39. }
  40.  
  41. #centerContent
  42. {
  43. background-color:black;
  44. width:60%;
  45. margin-left:1%;
  46. float:left;
  47. border:1px solid green;
  48. border-bottom:none;
  49. }
  50.  
  51. #rightContent
  52. {
  53. float:right;
  54. background-color:fuchsia;
  55. border:1px solid red;
  56. width:10%;
  57. }
  58.  
  59. /* ................................... STYLES ......................................... */
  60.  
  61. p.first-letter:first-letter
  62. {
  63. color:red;
  64. margin-left:5%;
  65. font-size:xx-large;
  66. }
  67.  
  68. p
  69. {
  70. font-family:Georgia, "Times New Roman", Times, serif;
  71. text-align:justify;
  72. margin:2% 3%;
  73. color:white;
  74. }
  75.  
  76. /* ................................... FOOTER ......................................... */
  77.  
  78. #footer
  79. {
  80. border:1px solid red;
  81. float:left;
  82. background-color:black;
  83. color:white;
  84. text-align:center;
  85. font-family:"Times New Roman", Times, serif;
  86. font-style:italic;
  87. font-size:large;
  88. width:100%;
  89. height:5%;
  90. margin:0px;
  91. }
Attached Thumbnails
result.jpg  
Nope, I'm NOT God, but I'm British (which is the next best thing ;)
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: PHP's include function ???

 
0
  #2
May 18th, 2006
Both your about page and menu.inc have <head> and <body> tags, which are invalid.

I will do it differently. I will either use a template or like what you did, but in the reverse way. I will have an index/default page with all the menus placed at the right position, and having content as include file.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 89
Reputation: j4mes_bond25 is an unknown quantity at this point 
Solved Threads: 0
j4mes_bond25's Avatar
j4mes_bond25 j4mes_bond25 is offline Offline
Junior Poster in Training

Re: PHP's include function ???

 
0
  #3
May 18th, 2006
Originally Posted by zippee
Both your about page and menu.inc have <head> and <body> tags, which are invalid.

I will do it differently. I will either use a template or like what you did, but in the reverse way. I will have an index/default page with all the menus placed at the right position, and having content as include file.
But wouldn't you say that "content" as "include" file, may not be possible, since the "content" would have to be DIFFERENT for different page, while the "include" function is for sharing the SAME content ALL OVER ???
Nope, I'm NOT God, but I'm British (which is the next best thing ;)
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 294
Reputation: zippee is an unknown quantity at this point 
Solved Threads: 6
zippee's Avatar
zippee zippee is offline Offline
Posting Whiz in Training

Re: PHP's include function ???

 
0
  #4
May 22nd, 2006
Ahh, forget to mention that you need to either use ?page=xxxx for each content or use mod_rewrite in .htaccess in this case to make the url look nicer. Many websites with large amount of content are managed in this way, including Daniweb.
Ecommerce-Web-Store.com Building Your e-Business.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC