Jump to content

Recommended Posts

I am working on a page and am using a simple include to use the same layout with different texts for every page.  When i created the links to all the pages i did it jsut like i've done on several other sites i've created but for some reason now it is just keeping the homepage text when i follow a link. Here is the code.

<a href="?id=pages/acid_stain.txt"><img src="images/index_08.gif" width="222" height="44"></a><br>
        <a href="?id=pages/epoxy.txt"><img src="images/index_09.gif" width="222" height="46"></a><br>
        <a href="?id=pages/paint_stain.txt"><img src="images/index_10.gif" width="222" height="45"></a><br>
        <a href="?id=pages/custom_design.txt"><img src="images/index_11.gif" width="222" height="44"></a><br>
        <a href="?id=pages/gallery.html"><img src="images/index_12.gif" width="222" height="46"></a><br>
        <a href="?id=pages/color_chart.html"><img src="images/index_13.gif" width="222" height="44"></a><br>
        <a href="?id=pages/contact.html"><img src="images/index_14.gif" width="222" height="47"></a></td>
        <td colspan="3"><img src="images/index_03.gif"
        width="520" height="13"></td>
        <td rowspan="12"><img src="images/index_04.gif"
        width="108" height="725"></td>
        <td><img src="images/spacer.gif" width="1" height="13"></td>
    </tr>
    <tr>
        <td rowspan="8" background="images/index_05.gif"> </td>
        <td align="center" valign="top" rowspan="8" width="498"><?php
if ($id == "") {
$id ="home.html";
}
include("$id");
?>

 

If anyone can help that would be great.

 

Also for some reason blue lines are appearing around the images/links. Does anyone know how i can get rid of those?

 

thanks in advance,

Craig

Link to comment
https://forums.phpfreaks.com/topic/67266-problem-with-including-but-why/
Share on other sites

You never define the $id variable. This....

 

<?php
if ($id == "") {
$id ="home.html";
}
include("$id");
?>

 

should be....

 

<?php
if ($_GET['id'] == "") {
$_GET['id'] = "home.html";
}
include($_GET['id']);
?>

 

PS: That code is extremely insecure. You need to validate that the files your including actually exist on your server. The way you have it setup anyone could run any php code they like on your site!

Ok, that code you supplied worked, but i have used it the other way and it used to work. 

 

How would i go about making it more secure?

 

And does anybody know how to get rid of the blue lines that go around the images/links?

 

I only have it up on a local server so i cant exactly show it to you, sorry.

The easiest way is to make an array of valid files. Something like...

 

<?php

  $valid = array('home.html','foo.html','bar/html');
  if ($_GET['id'] == "") {
   $_GET['id'] = "home.html";
  }
  if (in_array($_GET['id'],$valid)) {
    include($_GET['id']);
  }

?>

Otherwise, you can use file_exists to validate a file.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.