View Full Version : simple php include/var question

11-08-2012, 06: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


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

can anyone help me with this?

ivebeen trying
<? php
$ext= ".txt";

but having no luck

11-08-2012, 06: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.


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.