passing a variable url to require once()

Discussion in 'PHP' started by amol.gupta, Nov 8, 2009.

  1. #1
    Hi,
    I am into a situation where I need to pass a variable URL retrieved from data base into the
    require_once() function.something like
    require_once($URL)
    I have not been able to find any solution to this
    Please help
     
    amol.gupta, Nov 8, 2009 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    Do you mena like that?
    1.php
    
    <?php
    $myVariable = "some value";
    require_once("./2.php");
    ?>
    
    PHP:
    2.php
    
    <?php
    echo $myVariable;
    ?>
    
    PHP:
    if you run 1.php you get "some value" echoed.
    Or do you want to include different files based on variable value?
     
    AsHinE, Nov 8, 2009 IP
  3. amol.gupta

    amol.gupta Member

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #3
    actually I want to store a URL into $myVarialbe
    and this URL must be passed into require_once()
     
    amol.gupta, Nov 8, 2009 IP
  4. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    what you did is just good
    example if you store "www.domain.com/file.php" in $url

    then you just do require_once($url);
     
    fairuz.ismail, Nov 8, 2009 IP
    amol.gupta likes this.
  5. amol.gupta

    amol.gupta Member

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #5
    it is not working this way.......require_once is not accepting a variable....
     
    amol.gupta, Nov 8, 2009 IP
  6. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    hmm normally u can.. what type of error did you get?
     
    fairuz.ismail, Nov 8, 2009 IP
  7. amol.gupta

    amol.gupta Member

    Messages:
    199
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #7
    okk...
    I was able to debug it
    Thanks a lot to all
     
    Last edited: Nov 8, 2009
    amol.gupta, Nov 8, 2009 IP
  8. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    u do it wrong

    it's require_once($a);
     
    fairuz.ismail, Nov 8, 2009 IP