Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    mpw
    mpw is offline
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 06:51 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    $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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •