Unstoppable Domains โ€” Get your daily AI drops report

Problem with PHP include, help?

NamecheapNamecheap
Watch

Sheldchenko

Established Member
Impact
0
Click her efor the site

AS you can see, I get some strange PHP error message instead of the file thats meant to be displayed. I am using the same technique I always do for PHP includes and it normally works, but its been awhile since I have done it so maybe I missed something. Anyone give me a hand?

NOTE: Site is not actually going to be a site, its for my computer course.

Thanks.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Can you please post line 63 of that file.

- Steve
 
0
•••
Hey Sheldchenko,

The file the script is trying to open is simply called ".htm" as stated in the error, so I'd say you've just mispelled the file you want to be included.

Heres an example of how to use include:
include("myfolder/myfile.htm");

All the best,
Rhett.
 
0
•••
Posting the code will help me help you.

-Steve
 
0
•••
You did main('.php'); somehow.. :|
 
0
•••
Yeah if you give the code we can help. remember this for future errors that u need help with also, so that u can get the answer ASAP.

looks like u have the wrong file name there though...
 
0
•••
Code for the whole page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>: JS Music LTD. : Providing the Best in Music Retail since 1998.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div align="center">
<table width="800" cellpadding="0" cellspacing="0" class="outertable">
<tr>
<td width="800" height="355" valign="top">

<table width="800" class="maintable">
<tr>
<td width="800" valign="bottom" class="logo">

<table width="800" border="0" cellpadding="0" cellspacing="0" class="topbuttons">
<tr>
<td width="150"><img src="images/buttons.jpg" alt="button"/></td>
<td width="150"><img src="images/buttons.jpg" alt="button"/></td>
<td width="150"><img src="images/buttons.jpg" alt="button"/></td>
<td width="150"><img src="images/buttons.jpg" alt="button"/></td>
<td width="150"><img src="images/buttons.jpg" alt="button"/></td>
</tr>
</table>

</td>
</tr>
<tr>
<td height="186" valign="top">
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="160" height="184" class="leftNavigation" valign="top">

<!-- Start of side links -->

<ul class="leftNav">
<li class="links"><a href="index.php?page=main">Home</a></li>
<li class="links"><a href="index.php?page=electric">Electrics</a></li>
<li class="links"><a href="index.php?page=acousticproduct">Acoustic</a></li>
<li class="links"><a href="index.php?page=ampsproducts">Amplifiers</a></li>
<li class="links"><a href="index.php?page=effectsproduct">Effects</a></li>
<li class="links"><a href="index.php?page=otherproducts">Other</a></li>
<li class="links"><a href="index.php?page=contact">Contact Us</a></li>
<li class="links"><a href="index.php?page=feedback">Feedback</a></li>
</ul>
<!-- End of side links -->

</td>
<td width="640" valign="top">

<!-- start of content -->

<div align="center">
<table cellpadding="0" cellspacing="0" class="content">
<tr>
<td height="28" background="images/content.jpg">ย </td>
</tr>
<tr>
<td>
<?php include ($page.".htm");?>
</td>
</tr>
</table>
</div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="21">ย </td>
</tr>
</table></td>
</tr>
</table>
</div>
</body>
</html>
 
0
•••
The $page variable has not been set.

So its trying to include just ".htm".
 
0
•••
What should I do then?
 
0
•••
What is the page's name that you want to include? If you want to get something like www.example.com/index.php?page=blah, and then include blah.htm, change

PHP:
<?php include ($page.".htm");?>

to

PHP:
<?php include ($_GET[page].".htm");?>

The $_GET superglobal stores the URL query variables.
 
0
•••
Thanks ,works fine now!
 
0
•••
oh and if u want to set a default page (meaning one that will be included without any $page variable set in the url) i suggest you put something like

if(!$_GET['page']) {
$page="home";
}
else {
$page=$_GET['page'];
}


and then that way, you can use $page instead of $_GET['page'] in your include blocks.
 
0
•••
cx409 said:
What is the page's name that you want to include? If you want to get something like www.example.com/index.php?page=blah, and then include blah.htm, change

PHP:
<?php include ($page.".htm");?>

to

PHP:
<?php include ($_GET[page].".htm");?>

The $_GET superglobal stores the URL query variables.
You are going to run into problems where people can run malicious code by sending harmful GET requests to your pages.

You might want to consider using switch function in PHP to designate the pages that are options. This way, you'll cut the chances that your site will be attacked with XSS.

Hope that made sense. If not, I'll try to explain it more.

-Steve
 
0
•••
Or, another solution is to put all the content pages into a folder called pages (or something) so that all the include functions have include("pages/".$page.".htm").

i heard that doing this prevents malicious codes from being run on websites.
 
0
•••
nasaboy007 said:
Or, another solution is to put all the content pages into a folder called pages (or something) so that all the include functions have include("pages/".$page.".htm").

i heard that doing this prevents malicious codes from being run on websites.
This would be an alternative to what I posted as well. You might consider using absolute URL's if possible.

-Steve
 
0
•••
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back