Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2012, 05:45 PM   PM User | #1
mpw
New to the CF scene

 
Join Date: Nov 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mpw is an unknown quantity at this point
Question simple php include/var question

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

Last edited by mpw; 11-08-2012 at 05:51 PM..
mpw is offline   Reply With Quote
Old 11-08-2012, 05:56 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
$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 Code:
<?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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
include, links, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:06 PM.


Advertisement
Log in to turn off these ads.