Include Issue

Discussion in 'PHP' started by bloard, Mar 31, 2007.

  1. #1
    I can't get include files to pick up variables from the "parent" script... like this:

    file1.php

    <? $state="illinois";
    include('http://www.mysite.com/file2.php');
    ?>

    file2.php
    <? echo $state; ?>

    It also doesn't work if i change the include url to: http://www.mysite.com/file2.php?state=$state, then do a GET on file2 to catch the parameter.

    Any ideas?
     
    bloard, Mar 31, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try using a relative URL.
     
    rodney88, Mar 31, 2007 IP
  3. bloard

    bloard Peon

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks.. that solution took about 1 min. Didn't think of that.
     
    bloard, Mar 31, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Just to add to that: 99.9% of the time, including via HTTP is wrong and won't work as expected. Well, it works as expected when you understand what is happening :)

    Always use filesystem paths unless you know WHY you're including via HTTP.
     
    TwistMyArm, Apr 1, 2007 IP
  5. metallic07039

    metallic07039 Peon

    Messages:
    272
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can always just download the HTML into a variable so you don't have to include via HTTP.
     
    metallic07039, Apr 1, 2007 IP
  6. KlearConcepts

    KlearConcepts Peon

    Messages:
    349
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I think the second problem you may need to have:
    
    include('http://www.mysite.com/file2.php?state=.' echo $state; .'');
    
    PHP:
    Instead of:

    http://www.mysite.com/file2.php?state=$state
     
    KlearConcepts, Apr 1, 2007 IP
  7. metallic07039

    metallic07039 Peon

    Messages:
    272
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You can't do that, it will give an error. This would work though:

    
    include('file2.php?state=' .  $state);
    
    PHP:
     
    metallic07039, Apr 1, 2007 IP
  8. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    lol..variables can't be passed via http unless you use a GET, POST COOKIE etc method.
     
    manilodisan, Apr 1, 2007 IP