1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

variable issues using includes

Discussion in 'PHP' started by david_sakh, Jan 12, 2005.

  1. #1
    $variable="blah";
    include("file.php"); ?>
    Code (markup):
    this works, allowing the included file to use the variable $variable

    but, I changed my include path to another directory:
    
    $variable="blah";
    include("http://www.site.com/directory/file.php"); ?>
    Code (markup):
    and it no longer works....$variable isn't recongized.

    Could this be resolved, and how can I refer to other folders above the current directory using a local path not using http://
     
    david_sakh, Jan 12, 2005 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Reference the file with the file path, not a URL. Doing it as a URL isolates it into it's own script. You would need to know the full path on the server... could be something like:

    /home/sites/site1/www/file or something along those lines.
     
    digitalpoint, Jan 12, 2005 IP
    david_sakh likes this.
  3. david_sakh

    david_sakh Peon

    Messages:
    1,225
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is this for security reasons?
     
    david_sakh, Jan 12, 2005 IP
  4. anton-io!

    anton-io! Active Member

    Messages:
    540
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #4
    this is a long shot, but try

    include '/directory/file.php';

    or

    include 'directory/file.php';


    http://ca.php.net/manual/en/function.include.php
     
    anton-io!, Jan 13, 2005 IP
  5. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #5
    I think, in general, if file.php is not in your server, you CANNOT do it. Because when you request a PHP file from an URL, the server will process that file and return the output.
    If I am not right, so I can easily hack other site by
    inlcude("http://www.theirserver.com/include.inc.php")
    PHP:
     
    goldensea80, Jan 13, 2005 IP
  6. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Is this correct? I have this issue here:

    http://forums.digitalpoint.com/showthread.php?t=7795

    and this answer might solve my problem. But isn't there a better way to include output from a different page? I basically ned to scrape a file's output.
     
    T0PS3O, Jan 13, 2005 IP
  7. xml

    xml Peon

    Messages:
    254
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    $pageData = file_get_contents('http://www.feedsfarm.com/');

    This will get the output of the page.
     
    xml, Jan 13, 2005 IP
  8. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #8
    I think that's correct. However, if your file's extension is not .PHP, that may works.
     
    goldensea80, Jan 13, 2005 IP
  9. david_sakh

    david_sakh Peon

    Messages:
    1,225
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #9
    oh, even more help in case i want to see some variables. :)

    I forgot to mention that shawn's solution did work, just use a local path.
     
    david_sakh, Jan 13, 2005 IP