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.

Issue with PHP include on subdomain

Discussion in 'PHP' started by Ian, Nov 13, 2012.

  1. #1
    I'm trying to include the following on a page on a subdomain, which is on the same server as the parent domain:

    <? include ("/home/httpd/vhosts/mydomain.com/httpdocs/file.php"); ?>
    PHP:
    Unfortunately the file doesn't open/execute, and the error I get when I check the error log is "Failed opening '/home/httpd/vhosts/mydomain.com/httpdocs/file.php' for inclusion".

    Again, since it's on a subdomain I'm just wondering if there's a permission issue or if there's something else that needs to be done that I'm just missing?
     
    Ian, Nov 13, 2012 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Probably has a directory restriction. What is the location of the file you are including from? Also, double check the permissions on the file you are trying to include.
     
    jestep, Nov 13, 2012 IP
  3. ironcladservers

    ironcladservers Well-Known Member

    Messages:
    389
    Likes Received:
    20
    Best Answers:
    4
    Trophy Points:
    115
    #3
    Have you checked for proper permissions/ownership of the files in question? As jestep stated, knowing where you're trying to include from would likely be good to know as well.
     
    ironcladservers, Nov 13, 2012 IP
  4. linkodev

    linkodev Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Have you been able to resolve the issue. Also check if you server supports php short tags. I see you using that which is not best practice.

    Thanks
     
    linkodev, Nov 15, 2012 IP
  5. liquidation31

    liquidation31 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    looks like you make a little mistake, i think the syntax should like :

    <?php include ("/home/httpd/vhosts/mydomain.com/httpdocs/file.php"); ?>
     
    liquidation31, Nov 19, 2012 IP
  6. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #6
    stephan2307, Nov 19, 2012 IP
  7. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #7
    Does this work?

    <?php include ("/file.php"); ?>
    PHP:
     
    scottlpool2003, Nov 19, 2012 IP
  8. liquidation31

    liquidation31 Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    liquidation31, Nov 19, 2012 IP
  9. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #9
    of ../file.php? one directory lower? of you need more then do this for every lower directory ../

    ../../../../file.php
     
    EricBruggema, Nov 19, 2012 IP
  10. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #10
    If we knew the actual path of the file from the root, the directory this file (the one this code is in) is in and the actual directory of the document root of the web server, we could write you a statement that should work. Since there are some hosts that set things up in strange ways, we can't assume anything.
     
    Rukbat, Nov 22, 2012 IP
  11. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #11
    Are you using Plesk or a similar VPS control panel???

    If you are on a subdomain the path to your httpdocs would be: /home/httpd/vhosts/mydomain.com/subdomains/subname/httpdocs/ if you are trying to include a file outside of your sundomains httpdocs (ie. in the main domain httpdocs: /home/httpd/vhosts/mydomain.com/httpdocs/file.php) you will need to reconfigure apache to allow this. Refer to this document: http://stackoverflow.com/questions/2370053/how-to-include-file-outside-document-root
     
    NetStar, Nov 26, 2012 IP
  12. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #12
    Dimes to dollars you're running the nonsense known as suPHP which makes php execute with the user permissions of the account/main directory. This typically means that even subdomains get their own user, preventing cross-domain use of files -- even server side.

    I call it nonsense because the only thing suPHP does over fastCGI is run each php instance as the user for the domain; which means sure, you can't have hacks cross domains on the server, but it also means you might as well change the permissions of every file to 777. Security-wise it's the equivalent of shooting your dog because the neighbor's cat has fleas. Sure, let's open up a massive gaping security hole in every account to prevent an ultra-rare tiny hole over there. It's like plugging a crack in a dam with a wrecking ball.

    If that is indeed the case, you're pretty much SOL... my advice, copy the one file to the same domain/subdomain instead of trying to cross domains.

    Though if that file calls other files, those files wouldn't be in scope anyways so those too would fail... even if you're not on suPHP.
     
    deathshadow, Nov 27, 2012 IP