PHP's include function ???

j4mes_bond25

New Member
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:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Alcohol - Main Page</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>

<body>
<div id="header">
<p>Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header. Header.</p>
</div>

<div id="topMenu">
<p>Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. Top Menu. </p>
</div>

<div id="leftContent">
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
<p>Left Menu.</p>
</div>

<div id="rightContent">
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
<p>Right Menu.</p>
</div>

<div id="centerContent">
<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>

<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>

<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>

<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>

<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>
 
</div>

<div id="footer">
Last Updated:
<script type="text/javascript">

<!-- Begin
var days = new Array(8);
days[1] = "Sunday";
days[2] = "Monday";
days[3] = "Tuesday";
days[4] = "Wednesday";
days[5] = "Thursday";
days[6] = "Friday";
days[7] = "Saturday";

var months = new Array(13);
months[1] = "January";
months[2] = "February";
months[3] = "March";
months[4] = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July";
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";

var dateObj = new Date(document.lastModified)
var wday = days[dateObj.getDay() + 1]
var lmonth = months[dateObj.getMonth() + 1]
var date = dateObj.getDate()
var fyear = dateObj.getYear()
if (fyear < 2000) 
fyear = fyear + 1900
document.write(wday + ", " + lmonth + " " + date + ", " + fyear)
// End -->
</script>
</div>



</body>
</html>

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

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>Alcohol - Main Page</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>

<body>
<?php include("menu.inc");?>

</body>
</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:

Code:
/* CSS Document */

body 
{
	background-color:black;
	background-attachment:fixed;
}

/* ........................................ HEADER ........................................ */

#header
{
	width:100%;
	border:1px solid red;
	text-align:center;
	background-color:blue;
}


/* ......................................... TOP MENU .................................... */

#topMenu
{
	width:100%;
	float:right;
	background-color:red;
	border:1px solid red;
}


/* ................................... CONTENT ................................................ */

#leftContent
{
	float:left;
	width:10%;
	border:1px solid red;
	background-color:green;
}

#centerContent
{
	background-color:black;
	width:60%; 
	margin-left:1%;
	float:left;
	border:1px solid green;
	border-bottom:none;
}

#rightContent
{
	float:right;
	background-color:fuchsia;
	border:1px solid red;
	width:10%;
}

/* ................................... STYLES ......................................... */

p.first-letter:first-letter
{
	color:red;
	margin-left:5%;
	font-size:xx-large;
}

p
{
	font-family:Georgia, "Times New Roman", Times, serif;
	text-align:justify;
	margin:2% 3%;
	color:white;
}

/* ................................... FOOTER ......................................... */

#footer
{
	border:1px solid red;
	float:left;
	background-color:black;
	color:white;
	text-align:center;
	font-family:"Times New Roman", Times, serif;
	font-style:italic;
	font-size:large;
	width:100%; 
	height:5%; 
	margin:0px;
}
 

StephanieCordray

New Member
Well, first off, you don't link a link to menu.inc, you add a command to the index.php file to include it. In addition, your links might not be 'about.php', 'links.php', and so on. There will be an index.php but the others may be called something else within the system you are using depending on how you set them up.

Also, you don't have your links defined in your .css which you should define. An example would be something like this:

a:link, a:visited {
font-size: 10px;
color: #FF9900;
text-decoration: underline;
font-family: Verdana, Arial, Helvetica, sans-serif;
}

a:hover {
color: #FF9900;
text-decoration: none;
}


a.category:link, a.category:visited {
color: #ED0516;
font-weight: bold;
}



a.category:hover {
color: #333333;

I just grabbed that chunk from one of the files I have on my computer so it's not complete. However, that shows you how they are typically set up. It helps define how links should be displayed.
 

j4mes_bond25

New Member
StephanieCordray said:
Well, first off, you don't link a link to menu.inc, you add a command to the index.php file to include it. In addition, your links might not be 'about.php', 'links.php', and so on. There will be an index.php but the others may be called something else within the system you are using depending on how you set them up.

Also, you don't have your links defined in your .css which you should define. An example would be something like this:

a:link, a:visited {
font-size: 10px;
color: #FF9900;
text-decoration: underline;
font-family: Verdana, Arial, Helvetica, sans-serif;
}

a:hover {
color: #FF9900;
text-decoration: none;
}


a.category:link, a.category:visited {
color: #ED0516;
font-weight: bold;
}



a.category:hover {
color: #333333;

I just grabbed that chunk from one of the files I have on my computer so it's not complete. However, that shows you how they are typically set up. It helps define how links should be displayed.

I'm terribly sorry to give you a wrong impression here. I must say, however, that I didn't exactly copy the codes given in the tutorial but merely copied the idea.

I don't have any links at the moment, however, I simply wanted to use PHP's "include" function to share the layout (since I'll add the content later on) "Header", "TopMenu", "LeftMenu" and "BottomMenu".

Anyhow, as far as the problem itself is concerned, it seems working perfectly well, just as I hoped.

I realised that I might have to save everything in PHP's default "phpfolder" (as you may've known that PHP has some sort of setting making the user to save their ".php" file in PHP's own default "phpfolder").

Then I saved my "about.php" along with "style.css" and "menu.inc" in the default "phpfolder".

Although simply running the "about.php" straight from my browser i.e. by typing "C:\Personal Website\about.php" doesn't work, I tried to run it through my "localhost" by browsing (address displayed on my browser: http://localhost:6789/pp33tt/Personal_Website/about.php), it works PERFECTLY WELL.

So other than having my Apache server open, do I HAVE to run my php pages this way OR is there any way, I can keep my "Personal Website" folder in my "C" drive directly, rather than coping it to PHP's "phpfolder" & THEN run it.

WHY do we ALWAYS HAVE TO save ".php" files in PHP's "phpfolder" ??? Can't we simply run ".php" file from ANY location on my computer (just as any ".html" page, for example ???
 

StephanieCordray

New Member
Not quite sure what you mean there. Most php requires a mysql database to run and generate the pages that you can view in your browser... that's how it dynamically calls up the pages... not all certainly but most... and usually those that don't are still generating a page of some sort but are more like php snippets. The database is what stores the tables and data that the php calls up to make a particular page.

I can't click that link and see your pages.
 

AliKat

New Member
Are you installing this on your own PC or on a server?

Either way you need to place your php files in the section where it can access the php utilities etc.

On my home PC you find the files in www/webroot

on my server you find the files in public_html

You can't run a .php file from anywhere on your PC, it has to be in the specific folder other wise it can't access the php.exe that apache is running.
 
Top