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]
changing an included file
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
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>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
You could also use this, though not recommended for obvious security issues, but good to know:
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.
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>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>