changing an included file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kananook
Forum Newbie
Posts: 2
Joined: Mon Aug 19, 2002 1:27 am

changing an included file

Post 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]
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Code: Select all

<?
$id = $_GET&#1111;'id'];
if($id == "index")&#123;
include('index.php');
&#125; else &#123;
include('other.php');
&#125;
?>
change page by clicking <a href="<?=$PHP_SELF;?>?id=index">here</a>
hope you get the right idea
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post 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&#1111;'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&#1111;'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.
Post Reply