Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Including .shtml & Javascript code in php pages 1

Status
Not open for further replies.

Delboy14

Programmer
Jun 21, 2001
213
GB
I currently have a template for a page which includes .shtml pages and Javascript code, when I add php code to this page and change the extension to .php from shtml, the page formatting changes, I know that I have to change the syntaxt in my include statements, but dont think I am doing it properly, This is the shtml code I am attempting to change to the php equivalent:

<code>
<!--#include virtual=&quot;/includes/topnav.shtml&quot; -->
<table border=&quot;0&quot; cellspacing=0 cellpadding=0 width=&quot;100%&quot; onMouseOver=&quot;allOff()&quot;>
<tr>
<td onMouseOver=&quot;allOff()&quot;height=&quot;53&quot;><img src=&quot;/images/header.jpg&quot; width=&quot;228&quot;height=&quot;52&quot;></td>
</code>

I have tried to repeat this using:
<code>
<?php include('/includes/topnav.shtml'); ?>
<table border=&quot;0&quot; cellspacing=0 cellpadding=0 width=&quot;100%&quot; onMouseOver=&quot;allOff()&quot;>
<tr>
<td onMouseOver=&quot;allOff()&quot; height=&quot;53&quot;><img src=&quot;/images/header.jpg&quot; width=&quot;228&quot; height=&quot;52&quot;></td>
</code>

I recieve two type of errors from this code,
1. The file is not included
2. I get run time errors on the JavaScript code eg. onMouseOver=&quot;allOff()&quot;

Does anyone know what I am doing wrong?
 
Code:
<!--#include virtual=&quot;/includes/topnav.shtml&quot; -->
That &quot;virtual&quot; part means look at the 'virtual / directory', ie, apache's DocumentRoot + the URI you specify. Set your PHP inlude_path to include that directory (ie, /var/ and you should be OK.

Also, a function I method I have found handy is to use:
Code:
 ini_set(&quot;include_path&quot;,&quot;<whateverpathyouneed&quot;);
in the head of some files. Put that in a conditional that checks the server's hostname, and you have an easy way to distinguish between your devel and production boxen ;-)
 
I have tried to use this:
<?php include (&quot;/includes/topnav.shtml&quot;); ?>

instead of
<!--#include virtual=&quot;/includes/topnav.shtml&quot; -->

in the php file but it is not included in the php output file, does nayone know why?
 
I dont know, I am quite new to php. This does work but I have been advised it sends a file to the server from another post, which said;

&quot;include includes a file on the server. You shouldn't specify the full URL to it.&quot;
 
Delboy14:

When PHP encounters an include() statement, it reads the file and includes it from the filesystem. Newer versions of PHP can do the same thing across the web.

If the URL in your example points to another web site, you are doing the right thing. If that URL points to a file on your own system, you are fetching in in the absolutely least effient way possible. In that case, change it so that it includes a filename, not a URL. Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top