HTML/PHP include files


T

tom_sawyer70

I cannot seem to get a navigation file included for subdocuments on my
site. I am running SuSE 10 with Apache 2 and PHP. I am new to html,
php and css, but trying to learn. I'm trying to get this first page
set to use as a template for the other members.

My css is setup as a two column layout (no tables).

For the following, the files are located under:
/srv/www/htdocs/index.php
/srv/www/htdocs/web.css
/srv/www/htdocs/includes/nav.php
/srv/www/htdocs/jennifer/jennifer.php

My include path in php.ini has /srv/www/htdocs/includes in it.

My /srv/www/htdocs/index.php file is:
-----------------------------------------------
<?php $thisPage='home';?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
<title>The Family Page</title>
<link rel="stylesheet" type="text/css" href="web.css" />
</head>

<body>

<div id="header">
<h1>The Family</h1>
</div>

<div id="nav">
<?php include ('nav.php'); ?>
</div>

<div id="content">
<h2>Welcome!</h2>
<img class="floatright" src="./jennifer/jennifer.jpg" width="90"
height="120" align="right" alt="Jennifer's Picture" />
<p>Welcome.</p>

<br></br>
<br></br>
<br></br>

<h2>Latest News and Information</h2>
<p>Improvements to this site.</p>

<h2>What's Coming Soon!</h2>
<p>More improvements to this site.</p>

</div>

</body>

</html>
----------------------------------------
This file displays correctly and my nav.php is displayed in the left
panel.

My /srv/www/htdocs/jennifer/jennifer.php file is:

<?php $thisPage='jennifer';?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
<title>The Family Page</title>
<link rel="stylesheet" type="text/css" href="../web.css" />
</head>

<body>

<div id="header">
<h1>The Family</h1>
</div>

<div id="nav">
<?php include ("includes/nav.php"); ?>
<p>
</div>


<div id="content">
<h2>Welcome!</h2>
<img class="floatright" src="jennifer.jpg" width="90" height="120"
align="right" alt="Jennifer's Picture" />
<p>Jennifer's page</p>

<br></br>
<br></br>
<br></br>

<h2>Latest News and Information</h2>
<p>Improvements to this site.</p>

<h2>What's Coming Soon!</h2>
<p>More improvements to this site.</p>

</div>

</body>

</html>
-----------------------------------------------------

This page does not give an error, displays properly in the css format,
but the nav.php does not show in the navigation panel. Nor does any
other php statement (an echo, for example). However, if I put an html
statement there, it displays in the left panel. My display errors is
running.

If I try an info.php test file, it displays my server settings.

If I try to adjust the path to the nav.php file with ../nav.php or ../
nav.php or nav.php (since it is in the include_path), none of them
work.

I've tried dumping all of the files in the same directory as the
index.php and changed their paths and I still cannot get anything php-
related to show in the left panel (where I want the section to show).

All of the files and directories are owned by apache:website and have
the same permissions.

What am I overlooking or missing to get the php code to work within
the subfolder file?

TIA.
 
Ad

Advertisements

J

Jon Slaughter

I cannot seem to get a navigation file included for subdocuments on my
site. I am running SuSE 10 with Apache 2 and PHP. I am new to html,
php and css, but trying to learn. I'm trying to get this first page
set to use as a template for the other members.

My css is setup as a two column layout (no tables).

For the following, the files are located under:
/srv/www/htdocs/index.php
/srv/www/htdocs/web.css
/srv/www/htdocs/includes/nav.php
/srv/www/htdocs/jennifer/jennifer.php

My include path in php.ini has /srv/www/htdocs/includes in it.

My /srv/www/htdocs/index.php file is:
-----------------------------------------------
<?php $thisPage='home';?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
<title>The Family Page</title>
<link rel="stylesheet" type="text/css" href="web.css" />
</head>

<body>

<div id="header">
<h1>The Family</h1>
</div>

<div id="nav">
<?php include ('nav.php'); ?>
</div>

<div id="content">
<h2>Welcome!</h2>
<img class="floatright" src="./jennifer/jennifer.jpg" width="90"
height="120" align="right" alt="Jennifer's Picture" />
<p>Welcome.</p>

<br></br>
<br></br>
<br></br>

<h2>Latest News and Information</h2>
<p>Improvements to this site.</p>

<h2>What's Coming Soon!</h2>
<p>More improvements to this site.</p>

</div>

</body>

</html>
----------------------------------------
This file displays correctly and my nav.php is displayed in the left
panel.

My /srv/www/htdocs/jennifer/jennifer.php file is:

<?php $thisPage='jennifer';?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>

<head>
<title>The Family Page</title>
<link rel="stylesheet" type="text/css" href="../web.css" />
</head>

<body>

<div id="header">
<h1>The Family</h1>
</div>

<div id="nav">
<?php include ("includes/nav.php"); ?>
<p>
</div>


<div id="content">
<h2>Welcome!</h2>
<img class="floatright" src="jennifer.jpg" width="90" height="120"
align="right" alt="Jennifer's Picture" />
<p>Jennifer's page</p>

<br></br>
<br></br>
<br></br>

<h2>Latest News and Information</h2>
<p>Improvements to this site.</p>

<h2>What's Coming Soon!</h2>
<p>More improvements to this site.</p>

</div>

</body>

</html>
-----------------------------------------------------

This page does not give an error, displays properly in the css format,
but the nav.php does not show in the navigation panel. Nor does any
other php statement (an echo, for example). However, if I put an html
statement there, it displays in the left panel. My display errors is
running.

If I try an info.php test file, it displays my server settings.

If I try to adjust the path to the nav.php file with ../nav.php or ../
nav.php or nav.php (since it is in the include_path), none of them
work.

I've tried dumping all of the files in the same directory as the
index.php and changed their paths and I still cannot get anything php-
related to show in the left panel (where I want the section to show).

All of the files and directories are owned by apache:website and have
the same permissions.

What am I overlooking or missing to get the php code to work within
the subfolder file?

TIA.

I can't be sure but chances are your paths are wrong.

Whe you do

<?php include ("includes/nav.php"); ?>

You are including w.r.t to the current path

i.e.

/srv/www/htdocs/jennifer/jennifer.php is the file and its looking for
nav.php at
/srv/www/htdocs/jennifer/includes/nav.php

Now if say nav.php is being included but includes inside nav.php still might
be wrong. (such as your style sheets).

I'm currently having a similar issue and trying to find a work around. You
can use absolutely paths but in my case I'm looking at a way that php can
modify the links inside the script.


i.e., in my case I have

root dir---
Index.php
Styles/Main.css
OtherDir/SomePage.php

Somepage.php includes index.php but index.php includes main.css

Now if I load up index.php it all works but when I include index.php into
SomePage.php I only get the contents of index.php but not the style sheet
because its trying to find the style sheet w.r.t to OtherDir instead of the
root dir.

e.g. Somepage loads Index.php as if it copied Index.php to OtherDir but
Index.php is then looking for OtherDir/Styles/Main.css which doesn't.

If you go into Index.php and use ../Styles/Main.css to get it to work with
SomePage then you break it when using Index.php(in most cases).


I cannot use absolute paths for a specific reason but I have yet to find a
solution.

Jon
 
T

Toby A Inkster

<?php include ("includes/nav.php"); ?>

Try:

<?php include ("nav.php"); ?>

Because you mentioned that the "includes" directory is in your
includes_path, but you didn't say that its parent directory was.

--
Toby A Inkster BSc (Hons) ARCS
http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
 
T

tom_sawyer70

I can't be sure but chances are your paths are wrong.

Whe you do

<?php include ("includes/nav.php"); ?>

You are including w.r.t to the current path

i.e.

/srv/www/htdocs/jennifer/jennifer.php is the file and its looking for
nav.php at
/srv/www/htdocs/jennifer/includes/nav.php

Jon,
Thank you for the reply. I have tried variations on the path,
including trying to go right to the file with
/srv/www.htdocs/includes/nav.php

or

http://localhost/includes/nav.php

Neither works.

The interesting thing is even if I try a basic php command, such as to
echo a string, I get no error or result. However, if I do an html
statement, such as <p>print here</p>, it works.
 
T

tom_sawyer70

Try:

<?php include ("nav.php"); ?>

Because you mentioned that the "includes" directory is in your
includes_path, but you didn't say that its parent directory was.

--
Toby A Inkster BSc (Hons) ARCShttp://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!


Toby,
Thank you for the reply. My include_path does include the parent
directory, and from info.php is:
..:/srv/www/htdocs:/srv/www/htdocs/includes:usr/share/php5:/usr/share/
php5/PEAR

My understanding of an include_path directive is that it is similar to
a DOS search path, in that if the file is not in the local directory
then the path is searched until it is found.

Dave
 
J

Jon Slaughter

Jon,
Thank you for the reply. I have tried variations on the path,
including trying to go right to the file with
/srv/www.htdocs/includes/nav.php

or

http://localhost/includes/nav.php

Neither works.

The interesting thing is even if I try a basic php command, such as to
echo a string, I get no error or result. However, if I do an html
statement, such as <p>print here</p>, it works.

ok:
not sure if this is the problem but your two php files are different:

<div id="nav">
<?php include ('nav.php'); ?>
</div>

in one you said works and


<div id="nav">
<?php include ("includes/nav.php"); ?>
<p>
</div>

in the one that you said didn't.


So it looks like an include problem. A path problem.

<?php include ("/includes/nav.php"); ?>

I know you said you already tried by try this again and see if it works. You
shouldn't have to set php's includes dir for this.

Try changing Index.php to
<?php include ("/includes/nav.php"); ?>

and see if it still works. IT SHOULD if / is the root. That is if when you
browse to http://hostIP/Index.php it should work and then
http://hostIP/Jennifer/Jennifer.php.

HostIP is the ip that your appache server uses(mine doesn't work with local
host by my LAN IP.

Make sure its not actually using nav. That is, use a temporary nav.php of
something like
<?php echo 'FROM /INCLUDES/NAV.PHP'?>

Then look at Index.php and the source and see if you can find it. I would
strip away all the html code except is what is necessary to troubleshoot the
code. Index.php and Jennifer.php should just contain

<?php include ("/includes/nav.php"); ?>

and nav.php should just contain

<?php echo 'FROM /includes/nav.php'?>

Then you can be sure of the results you get. It should work in both unless
or niether. If it works from niether then your root directory isn't '/' but
something like '/htdocs' so you'll need to change it.


Your issue is that your tring to load up nav.php in jennifer.php in

/srv/www/htdocs/jennifer/jennifer/includes/nav.php

-jennifer.php-
<div id="nav">
<?php include ("includes/nav.php"); ?>
<p>
</div>

But obviously that file doesn't exist there. You can check this easily to
see if its the problem by copying your includes dir to the jennifer dir and
see if everything works. If it does then either do

<div id="nav">
<?php include ("../includes/nav.php"); ?>
<p>
</div>

or use the absolute paths above(make sure to delete jennifer/includes so you
don't get false results).


Hopefully something there helped. I would try to start from scratch. It
seems I had the exact same issue but I got confused because I forgot to
change all paths to absolute and so some of the relative paths were making
it look like it didn't work... so I spend about an hour trying to figure out
the problem and then saw I had more links that I forgot to make absolute.
Once I did that everything worked.

Jon
 
Ad

Advertisements

T

tom_sawyer70

ok:
not sure if this is the problem but your two php files are different:

<div id="nav">
<?php include ('nav.php'); ?>
</div>

in one you said works and

<div id="nav">
<?php include ("includes/nav.php"); ?>
<p>
</div>

in the one that you said didn't.

So it looks like an include problem. A path problem.

<?php include ("/includes/nav.php"); ?>

I know you said you already tried by try this again and see if it works. You
shouldn't have to set php's includes dir for this.

Try changing Index.php to
<?php include ("/includes/nav.php"); ?>

and see if it still works. IT SHOULD if / is the root. That is if when you
browse tohttp://hostIP/Index.phpit should work and thenhttp://hostIP/Jennifer/Jennifer.php.

HostIP is the ip that your appache server uses(mine doesn't work with local
host by my LAN IP.

Make sure its not actually using nav. That is, use a temporary nav.php of
something like
<?php echo 'FROM /INCLUDES/NAV.PHP'?>

Then look at Index.php and the source and see if you can find it. I would
strip away all the html code except is what is necessary to troubleshoot the
code. Index.php and Jennifer.php should just contain

<?php include ("/includes/nav.php"); ?>

and nav.php should just contain

<?php echo 'FROM /includes/nav.php'?>

Then you can be sure of the results you get. It should work in both unless
or niether. If it works from niether then your root directory isn't '/' but
something like '/htdocs' so you'll need to change it.

Your issue is that your tring to load up nav.php in jennifer.php in

/srv/www/htdocs/jennifer/jennifer/includes/nav.php

-jennifer.php-
<div id="nav">
<?php include ("includes/nav.php"); ?>
<p>
</div>

But obviously that file doesn't exist there. You can check this easily to
see if its the problem by copying your includes dir to the jennifer dir and
see if everything works. If it does then either do

<div id="nav">
<?php include ("../includes/nav.php"); ?>
<p>
</div>

or use the absolute paths above(make sure to delete jennifer/includes so you
don't get false results).

Hopefully something there helped. I would try to start from scratch. It
seems I had the exact same issue but I got confused because I forgot to
change all paths to absolute and so some of the relative paths were making
it look like it didn't work... so I spend about an hour trying to figure out
the problem and then saw I had more links that I forgot to make absolute.
Once I did that everything worked.

Jon

Jon,
ARGH (this is why I don't program for a living). I kept thinking
about the fact that no php commands were working and eventually
stumbled across my dilemna. My nav.php file was called
"jennifer.html," rather than "jennifer.php."

I thought that I could include an html file from a php statement
(above, my syntax was wrong...the jennifer.php was actually
jennifer.html) and that php would just embed the html, but the only
change I made from it "not working" to "working" is renaming the
*.html file to *.php. Ironically, a colleague also looked at the code
visually and through Dreamweaver and said that everything looked all
right. I seem to recall from some of the tutorials that including an
html file was acceptable, but maybe not...or I have a directive that
is interfering. Anyway, this is a big thorn out of my side.

I appreciate your assistance and input.

Dave
 
Ad

Advertisements

J

Jon Slaughter

Jon,
ARGH (this is why I don't program for a living). I kept thinking
about the fact that no php commands were working and eventually
stumbled across my dilemna. My nav.php file was called
"jennifer.html," rather than "jennifer.php."

I thought that I could include an html file from a php statement
(above, my syntax was wrong...the jennifer.php was actually
jennifer.html) and that php would just embed the html, but the only
change I made from it "not working" to "working" is renaming the
*.html file to *.php. Ironically, a colleague also looked at the code
visually and through Dreamweaver and said that everything looked all
right. I seem to recall from some of the tutorials that including an
html file was acceptable, but maybe not...or I have a directive that
is interfering. Anyway, this is a big thorn out of my side.

lol. Yeah, I think everyone makes that mistake at first. I know I did. When
you include html it is processed as html.

There is something about that on the help

http://us2.php.net/include/


"When a file is included, parsing drops out of PHP mode and into HTML mode
at the beginning of the target file, and resumes again at the end. For this
reason, any code inside the target file which should be executed as PHP code
must be enclosed within valid PHP start and end tags."


Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top