USING a variable in include

Discussion in 'PHP' started by SurfHide.us, Jan 21, 2012.

  1. #1
    Here is a code that i tried to design but it wornd work.. can someone plz tell me what m i doing wrong?

    
    <?php 
    $folder=$_GET['folder'];
    include ('.$folder.'/main'.php');
     ?>
    PHP:
     
    SurfHide.us, Jan 21, 2012 IP
  2. yho_o

    yho_o Well-Known Member

    Messages:
    354
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    #2
    
    <?php 
        if(isset($_GET['folder']) && !empty($_GET['folder'])){
            $folder= $_GET['folder'];
            include ($folder . "/main.php");
        }else{
            echo "Hello there!";
        }
    ?>
    
    PHP:
    Note: Make sure to verify the $_GET[] values and make it open only certain pages/folders or otherwise you'll make hackers access other folders/files

    Thanks
     
    yho_o, Jan 21, 2012 IP
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    Assuming you have ?folder=something
    <?php
    $folder=$_GET['folder'];
    include ("$folder/main.php");
    
     ?>
    PHP:
    Or as above run a check
     
    MyVodaFone, Jan 21, 2012 IP