...

View Full Version : simple php include/var question



mpw
11-08-2012, 05:45 PM
hello im new to webdesign and am just learning php. id like to do my links using a php variable and txt files. with the url looking like

mysite.com/index.php?var=link

which would load link.txt without having the ".txt" in my url.

can anyone help me with this?

ivebeen trying
<? php
$ext= ".txt";
include("$var$ext");
?>

but having no luck

Fou-Lu
11-08-2012, 05:56 PM
$var only exists in a deprecated register_globals environment. That said, NEVER include directly off of a url request without checking if it exists and is what you want.



<?php

if (isset($_GET['var']))
{
$sFile = basename($var) . '.txt';
include $sFile;
}


You should add additional rules as well. Jail it to a specific directory, do not allow relative paths (basename will only take the filename anyway), etc.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum