Forum Moderators: mack

Message Too Old, No Replies

Using #include

what am i doing wrong?

         

Andrew Thomas

1:48 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



Hi, im trying to create a dynamic site,

I have a .htm file called 'header.htm' which contains my navigation and logo

The other page which im inserting my 'header' using the #include is called 'index.asp'

The problem is when i use Dreamweaver, the included file 'header.htm' appears correct in the index.asp file, but when i try and add more contect below this it wont let me.

here is the code for index.asp

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--#include virtual="header.htm"-->
</head>

<body>

</body>
</html>

and code for header.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body background="images/background.jpg">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" background="images/top-back.jpg">
<tr>
<td width="30%" height="115" rowspan="3"><div align="center"><img src="images/butterfly.jpg" width="173" height="115" align="top"></div></td>
<td width="26%" rowspan="3"><img src="images/adas.jpg" width="176" height="115"></td>
<td width="44%" valign="top"><div align="center"><img src="images/alcohol.jpg" width="302" height="30" align="top"></div></td>
</tr>
<tr>
<td valign="bottom">service contacts us</td>
</tr>
</table>
<p>&nbsp;</p></body>
</html>

What am i doing wrong, as i cannot put anything in the body of the index.asp file

thanks

JuDDer

2:04 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



Does your header.htm have anything like <html> <title> <body> (opening or closing) tags in it?
If so, try removing that from the header as your index.asp page will most likely already have it in there.

<edit>
I just re-read your message and it's obvious that you do have <head> etc tags in there - try removing them from the include file.
</edit>

Also, when working with includes you need to remember that you can do it two ways:

<!--#include file="header.htm"-->

This expects your header.htm to be in the same folder as all pages calling it.

On the other hand:

<!--#include virtual="/header.htm"-->

Is what I prefer as it allows me to always reference it from the root.

korkus2000

2:07 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First I would call your header either header.inc or header.asp. You have double header content here. The include is seemlessly added. This is what you are creating:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<!--/////////// Start Header \\\\\\\\\\\\\\-->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body background="images/background.jpg">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" background="images/top-back.jpg">
<tr>
<td width="30%" height="115" rowspan="3"><div align="center"><img src="images/butterfly.jpg" width="173" height="115" align="top"></div></td>
<td width="26%" rowspan="3"><img src="images/adas.jpg" width="176" height="115"></td>
<td width="44%" valign="top"><div align="center"><img src="images/alcohol.jpg" width="302" height="30" align="top"></div></td>
</tr>
<tr>
<td valign="bottom">service contacts us</td>
</tr>
</table>
<p>&nbsp;</p></body>
</html>
<!--/////////// End Header \\\\\\\\\\\\\\-->
</head>

<body>

</body>
</html>

You are closing your document in the header. I would try something like:

Header include(header.inc):

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body background="images/background.jpg">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" background="images/top-back.jpg">
<tr>
<td width="30%" height="115" rowspan="3"><div align="center"><img src="images/butterfly.jpg" width="173" height="115" align="top"></div></td>
<td width="26%" rowspan="3"><img src="images/adas.jpg" width="176" height="115"></td>
<td width="44%" valign="top"><div align="center"><img src="images/alcohol.jpg" width="302" height="30" align="top"></div></td>
</tr>
<tr>
<td valign="bottom">service contacts us</td>
</tr>
</table>
<p>&nbsp;</p>

Asp pages(default.asp):

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--#include virtual="header.inc"-->
<!--///////////// Start Content \\\\\\\\\\\\\\\\\\\-->

<!--///////////// End Content \\\\\\\\\\\\\\\\\\\-->
<!--#include virtual="footer.inc"-->

Footer include(footer.inc):
<!--//// Bottom navigation, copyright, and other global bottom info \\\\-->
</body>
</html>

<added>

Also, when working with includes you need to remember that you can do it two ways:

<!--#include file="header.htm"-->

This expects your header.htm to be in the same folder as all pages calling it.

On the other hand:

<!--#include virtual="/header.htm"-->

Is what I prefer as it allows me to always reference it from the root.

This is also important. If you have folders with pages then it has to be done without breaking the page.
</added>

JuDDer

2:22 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



To comment on korkus2000's reply, I would always advise against naming a file with a .inc extension.

If you were to have asp code in your include file which contains database connection scripts etc and name it as .inc, there is the possibility that somebody will find this file and be able to read your database connection passwords as plain text.

If the include file was names with a .asp extension, nothing would output in this scenario thus securing your database conntection or whatever is in the script.

I have seen many instances of search engines indexing .inc files that include sensitive information when the .inc file does not execute correctly and is able to be indexed.

korkus2000

2:37 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



JuDDer why not use the global.asa instead of includes for that? I have always had a programmer create a component for that kind of security.

Andrew Thomas

2:49 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



Thanks for yor replies, it now works fine!

I now understand what you are saying, i was getting confused and using the tags in both the included and asp page.

I will know for next time

thanks again

JuDDer

4:12 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



Korkus2000, using the database connection was merely an example of what could be displayed in a .inc file - in reality it could be anything.

I personally wouldn't like anybody to poke around in my server side code.

Andrew Thomas

4:20 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



Well i thought it worked fine....

In dreamweaver the file appears correctly, but when i upload it to the webserver i get:

HTTP 500 - Internal server error
Internet Explorer

Any ideas

thanx

Marcia

4:32 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<!--#include file="header.htm"-->

My includes never work unless I have that extra space before the --> like this:

<!--#include file="header.htm" -->

I also have to add the filetype in .htaccess so it'll work with .htm in addition to .shtm but that's Apache. Try adding the space and see if that helps. It looks wrong but it's supposed to be there.

JuDDer

4:34 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



Does it give you any extra info about the problem?

In IE, you can click tools > Internet Options > Advanced then uncheck 'show friendly HTTP error messages'.

If you've not done this already, this should give more info about the error.

korkus2000

4:35 pm on Sep 12, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you using any other asp code on the pages besides the includes?

kastro

6:14 pm on Sep 12, 2002 (gmt 0)

10+ Year Member



<--- Just a little information I picked up along the way -->

Don't assume your global.asa file is secure either. If anything its more vulnerable then using a .asp file for connecting to a db. There are ways to read the global.asa without using a browser to see a plain text version of it.

check this book Hacking Web Applications Exposed for some more info.

Andrew Thomas

10:45 am on Sep 13, 2002 (gmt 0)

10+ Year Member



Just saying thanks again, i turned off 'show friendly HTTP error messages' and the error came up straight away 'very usefull' thanks judder and it was and old .inc file i wasnt using!

And also the space corrected another problem, thanks Marcia.