include php with id

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

  1. #1
    hello guys,
    I want to include a php file like include("p.php?id=1") but I get an error.
    is there any alternatives to use a function like that?
     
    jonhyhar, Dec 9, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2

    If you are including a file, it is local to the file/function/class you are including it in - any variables that are in scope will be accessible.

    I.E
    if p.php is;
    <?php
    print "ID = $id\n";
    ?>
    PHP:
    and you call it from;
    <?php
    $id = 1;
    include 'p.php';
    ?>
    
    PHP:
    $id is still in scope, so the result is;

    ID = 1

    This includes query vars and such.
     
    lukeg32, Dec 9, 2010 IP
  3. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    i know this way but it's not only p.php. there are profile.php?id=1, video.php?id=[number] etc

    I need to include these pages into loader.php

    i.e
    a site url is somesite.com/simple.php#!/profile.php?id=1

    loader.php becomes like,
    <?
    $page = $_GET['page']; // now $page is profile.php?id=1
    include($page);
    ?>
     
    jonhyhar, Dec 9, 2010 IP
  4. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #4
    
    $parts = parse_url($_GET['page']);
    $pieces = explode('=', $parts['query']);
    $$pieces[0] = $pieces[1];
    print_r($id);
    include($parts['path']);
    
    Code (markup):
    I hope this help
     
    drctaccess, Dec 9, 2010 IP
    jonhyhar likes this.
  5. jonhyhar

    jonhyhar Active Member

    Messages:
    166
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    thank you very much drctaccess it works very well :)
     
    jonhyhar, Dec 9, 2010 IP