Page 1 of 1
changing an included file
Posted: Mon Aug 19, 2002 1:27 am
by kananook
is thier a way to change an included file by clicking on a link?
ie change included file from "news.txt" to "updates.txt" by clicking HERE?[/b]
Posted: Mon Aug 19, 2002 1:36 am
by hob_goblin
Code: Select all
<?
$id = $_GETї'id'];
if($id == "index"){
include('index.php');
} else {
include('other.php');
}
?>
change page by clicking <a href="<?=$PHP_SELF;?>?id=index">here</a>
hope you get the right idea
Posted: Mon Aug 19, 2002 7:44 am
by fatalcure
yes, thats one of the simplest uses for php and developing a simple site management script using includes.
as stated above, simple If statements do the work for you
Code: Select all
<?php
$section = &$_GETї'section'];
if ($section == "A") include("A.txt");
else if ($section == "B") include ("B.txt");
else if ($section == "C") include ("C.txt");
else include("default.txt");
?>
<a href="?section=A">Section A</a><br>
<a href="?section=B">Section A</a><br>
<a href="?section=C">Section A</a><br>
You could also use this, though not recommended for obvious security issues, but good to know:
Code: Select all
$section = &$_GETї'section'];
if (file_exists("$section.txt")) include("$section.txt");
else include("default.txt");
<a href="?section=A">Section A</a><br>
<a href="?section=B">Section A</a><br>
<a href="?section=C">Section A</a><br>
the obvious flaw with this is that anyone can replace the $section variable in the address bar and can navigate through your folders etc, so I dont recommend the 2nd one, put just put it here for a need to know basis.