php question

Associate
Joined
11 Oct 2008
Posts
268
hey guys, for years ive been using a bit of code i found to include my news page and set my links up, its this bit of code

<?php
if(!$rpg || $rpg == ""){$rpg = "sector04";}
if(file_exists("$rpg.html")){
include ("$rpg.html");
} elseif (file_exists("$rpg.php")){
include ("$rpg.php");
} elseif (file_exists("$rpg.txt")){
include ("$rpg.txt");
} elseif (file_exists("$rpg")){
include ("$rpg");
} else{
include ("news.php");
}
?>


Ive just changed servers and for some reason none of my links work anymore, i know this code is pretty old, so im guessing theres a different way to do this with php 5, does anyone know what i have to change to get it working? thanks for any help :)
 
Are these from get variables? http://www.x.com/?rpg=page1 ?

If so try:
Code:
<?php
$rpg = preg_replace("/[^a-zA-Z0-9_-]/", "", $_GET['rpg']);

if(!$rpg || $rpg == ""){$rpg = "sector04";}
if(file_exists("$rpg.html")){
include ("$rpg.html");
} elseif (file_exists("$rpg.php")){
include ("$rpg.php");
} elseif (file_exists("$rpg.txt")){
include ("$rpg.txt");
} elseif (file_exists("$rpg")){
include ("$rpg");
} else{
include ("news.php");
}

If that works it's because the new server has register globals disabled, because they're very nasty :).
 
Last edited:
Back
Top Bottom