Got a little techonology problem that you need fixed pronto? Post it here and we'll see what we can do.
Topic locked

don't want iframes

Sun Aug 15, 2004 1:24 am

i don't want to use iframes, is there still a way to display content from a different page on the main page? i can use php scripts if neccessary.

Sun Aug 15, 2004 3:56 am

Code:
 Top of page/navigation

<div>
<? include "page_to_be_displayed.html(or .php)"; ?>
</div>

Bottom stuff like copyright etc.


you can format that however you want. My page is as follows (well on of my pages ):
Code:
<?
session_start();
include "db.php";
function content()
   {
   switch( $_GET['id'] ) {
      case '1' :
             include 'general.php';
           break;
      default:
             include 'index.php';
           break;
      }
   }
/*function buy()
   {
   switch( $_GET['action'] ) {
      case 'buy' :
             include 'buy.php';
           break;
      default:
             include 'index.php';
           break;
      }
   }
*/
?>
<html>
<head>
<title>.:`~Infinite Opportunities~`:.</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="100%">
<tr>
<td>
<img src="../images/banner.gif">
<br />
</td>
</tr>
<tr>
<td>
<table width="65%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top">
   <TABLE WIDTH=173 BORDER=0 CELLPADDING=0 CELLSPACING=0>
   <TR>
      <TD>
         <IMG SRC="../images/link_01.gif" WIDTH=173 HEIGHT=22 ALT=""></TD>
   </TR>
   <TR>
      <TD background="../images/link_02.gif" width="173" height="20" style="background-repeat: repeat-y;">
         <div width=170 style="position: relative; left: 3;">
                    <?
         include "../links.php";
         ?>
                  </div>
         <!--<IMG SRC="../images/link_02.gif" WIDTH=173 HEIGHT=20 ALT="">--></TD>
   </TR>
   <TR>
      <TD>
         <IMG SRC="../images/link_03.gif" WIDTH=173 HEIGHT=10 ALT=""></TD>
   </TR>
</TABLE>
   </td>
    <td valign="top">
   <TABLE WIDTH=570 BORDER=0 CELLPADDING=0 CELLSPACING=0>
   <TR>
      <TD>
         <IMG SRC="../images/content_01.gif" WIDTH=570 HEIGHT=30 ALT=""></TD>
   </TR>
   <TR>
      <TD background="../images/content_02.gif" WIDTH=570 HEIGHT=52 style="background-repeat: repeat-y;">
         <div width=567 style="position: relative; left: 3;">
                    <?
         content();
         //buy();
         ?>
                  </div>
         <!--<IMG SRC="../images/content_02.gif" WIDTH=570 HEIGHT=52 ALT="">--></TD>
   </TR>
   <TR>
      <TD>
         <IMG SRC="../images/content_03.gif" WIDTH=570 HEIGHT=30 ALT=""></TD>
   </TR>
</TABLE>
</td>
  </tr>
</table>
</td>
</tr>
</table>
</body>
</html>


thats pretty much a suped up version.
basically, it checks for the HTTP variable 'id' (http://www.afdafasf.com/home.php?id=1)
if and only if id = 1 will the page general.php be displayed. otherwise index.php will be displayed (default).
All of the html is just the 'pretty' part of the layout.

If that doesn't help then post here and i will simplify it(im just too lazy to type more right now).

Sun Aug 15, 2004 10:05 am

don't use the short tag <?, it doesn't work on all hosts, and messed up things with XML, which you write as <?xml. Instead use <?php.

if you just want to include something somewhere, not something that needs changing:
<?php include('the_thing_you_want_to_include'); ?>

Sun Aug 15, 2004 2:39 pm

just for a short script to include any page from the address bar(for exampel if you have ( http://www.blah.com?page=mypage1 ) i use

Code:
<?php
$defPage = "Put Default Page Here"; // default page if others arent valid
$ext     = ".php"; // your default extention, such as .html or . php
$page    = isset($HTTP_GET_VARS['page']) ? $HTTP_GET_VARS['page'] : (isset($HTTP_POST_VARS['page']) ? $HTTP_POST_VARS['page'] : $defPage);

if(file_exists($page . $ext))
{
    include($page . $ext);
}
else
{
    include($defPage . $ext);
}

unset($page, $defPage, $ext);
?>



put that inside of your html where you want the pages to show up

i really hope that helps, if you need anymore help just ask, IM me or something

Sun Aug 15, 2004 7:41 pm

since we're on the topic (kinda :)) of not all hosts doing the same thing i thought i would say that $_GET['whatever'] might not work. Do what stoodder did and use $HTTP_GET_VARS['whatever']. The main reason i don't do what stoodder did (the pagename in the url "www.blah.com?page=mypage1") is because then the user can try going to mypage1.php/html/htm/etc and the layout would be messed up. Then you would have to do some other coding to prevent that...

Thu Aug 19, 2004 2:12 am

unclekyky wrote:since we're on the topic (kinda :)) of not all hosts doing the same thing i thought i would say that $_GET['whatever'] might not work. Do what stoodder did and use $HTTP_GET_VARS['whatever']. The main reason i don't do what stoodder did (the pagename in the url "www.blah.com?page=mypage1") is because then the user can try going to mypage1.php/html/htm/etc and the layout would be messed up. Then you would have to do some other coding to prevent that...


yep i totally agree, that an offsite user can use php injection to hack asite, ive been tyring to expirment with phph injection(not to hack a site but for security reasons) i guess what i would do to fix that is add right after the $page =

add
$page = htmlspecialchars($page);

then also add into the if statement
if(file_exists($page) && !preg_match("/:\/\//", $page)

the first part gets rid of any unwanted html characters or slashes that might mess with your code and the second part in the preg_match look for :// (such as in http:// or ftp://) to make sure the user isnt trying to grab a file off of another site

Re: don't want iframes

Thu Aug 19, 2004 5:20 am

kwo_dude wrote:i don't want to use iframes, is there still a way to display content from a different page on the main page? i can use php scripts if neccessary.

You can't do it in the same way as iframes -- the browser will have to reload the whole page to update a part of it (so there's no easy "open this page in this space" without iframes).


$HTTP_GET_VARS (PHP 3, 4) is superceded by $_GET (PHP 4, 5). If you really want to do your homework, check which one is set (and not just lock your script to older versions of PHP).
Filtering :// is clever, but you'll have to filter all the slashes to make anything even relatively secure (if both your indexes are index.php, you can cause an infinite include in a rather nasty way).

Thu Aug 19, 2004 2:56 pm

thus hunter proves me wrong XD, well i guess another fast sollution i have is to use a switch statement like unclekyky said lol the only problem i have with that is you always have to update it when you add new pages. Otherwise if you dont feel liekusing an switch statement, to stop them from reincluding index.php do somethng like this:

$page = strtolower($page);
if($page=="index")
{
$page = $defpage;
}


so your final code shoudl look something like this:

Code:
Code:

<?php
$defPage = "Put Default Page Here"; // default page if others arent valid
$ext     = ".php"; // your default extention, such as .html or . php
$page    = isset($HTTP_GET_VARS['page']) ? $HTTP_GET_VARS['page'] : (isset($HTTP_POST_VARS['page']) ? $HTTP_POST_VARS['page'] : $defPage);
$page    = htmlspecialchars($page);
$page    =strtolower($page);

if($page == "index")
{
    $page = $defpage;
}

if(file_exists($page . $ext) && !preg_match("/:\/\//", $page))
{
    include($page . $ext);
}
else
{
    include($defPage . $ext);
}

unset($page, $defPage, $ext);
?> 


hopefully that is all, anyone see any others?
Topic locked