I'm familiar with include() or require() to include files in a script.
I need to achieve the same effect as include(), but with a file on a remote domain.

So basically, I need to get this to work:
include("http://www.someserver.com/somefile.php");

It doesn't work as the PHP file gets parsed as PHP when included, because the file doesn't reside on my own domain.

    I don't believe this is possible. because if you think about it, if you could do this... you could include anybodys code php code and then see the code! there server will never send the code, just the input.

    PHP needs to have a local refence to a file. so on the same computer, i guess network drives would work aswell.

      Hmmm... yeah, I know. But still. I don't want to rename my php files to .inc files.

      Isn't it possible through Curl? I'm not familiar with curl but I hoped someone here could tell me whether or not it's possible, so then I could dig into curl.

        hmm, sorry i'm not familiar with curl either.

        Why cant you just host it all in the same place?

          You should copy the file to your local source code and incorporate it into your application.

          Then you can use its functions, and you're neither dependent on the remote server to continue to work, or at the mercy of its continued security.

          include()ing a URL doesn't do what you think it does, and is always wrong.

          Mark

            I have several (20+) domains that use the same class for a script I wrote.
            I could copy the class file to every domain, but I'm doing regular updates to that class and if I put the class file on every domain, I would have to overwrite the file 20 times on different domains.

            That's why I include it over http. It works now when using a .inc extension for my class file (as .inc doesn't get parsed when included). But of course that's not really ok cause .inc files are readable by everyone.

            So basically you guys are telling me that something like this is NOT possible? Not even using CURL?

              If it was possible, then your code would still be readable by everyone. However, if all the domains are on one website, you could try placing it outside the document root in some shared directory, and have the file included by each domain.

                laserlight wrote:

                If it was possible, then your code would still be readable by everyone.

                Hmmm, right! 🙂

                laserlight wrote:

                However, if all the domains are on one website, you could try placing it outside the document root in some shared directory, and have the file included by each domain.

                My domains aren't on the same server, so I guess it's impossible to have a commonly shared folder outside the document root.

                  Maybe use the [man]FTP[/man] functions?

                    Even with several sites, you can still use copies of the same source, provided you have a build process for deployment of these many sites which uses the source code from the same place in your version management system.

                    You wouldn't then need to let them become out of sync any more than necessary, your build system can keep track of what version is deployed on to each site, and when you do new deployments, your build script could automatically pull the latest one out of source control.

                    Or something.

                    Anyway, think about it. It's only one file.

                    Having parts of the source of a web app updated at different times sounds like a recipe for disaster- it's important to be able to thoroughly test after each update, even if this is only of a component.

                    Loading the file at runtime from another server is definitely a bad idea.

                    Mark

                      Thanks for the insight Mark. It's good to know that my initial idea is not possible (and not secure). I'll dive into the build system I guess. You're right that it's now just one file, but I'm sure it'll grow in time to a few more class files.

                      Edit: I'm curious how you guys work with builds. Do you manually keep track of updates in the files, or do you use some kind of automated process, software even?

                        a month later

                        Hi,

                        I've just read this thread and you're trying to do exactly the same as me. I'm so relieved I've finally found some sort of confirmation that it's not possible.

                        About the method of changing the included files to .inc files - is there a way to secure the access to these files to make this a viable method? I'm guessing there probably isn't.

                        I'm also very interested in what other people use/do for build tracking. Are there any miniapps that manage this kind of thing? One that also manages ftp uploads would be the ultimate I guess! What takes the time is logging into each ftp area and uploading the files on 7 different servers (and growing).

                          inc files arent readable to everyone if u do it right... place the inc file in a specific directory... put an htaccess file in there requiring user authentication... then using curl you can retrieve the file by passing the correct login information

                          .htaccess

                          <files myclass.inc>
                          AuthType Basic
                          AuthName "Private"
                          AuthUserFile /usr/local/apache/passwd/passwords
                          Require user semtex
                          </files>
                          

                          something like that.. then use curl to access it.. nice and simple way to have it on one server

                            scrupul0us wrote:

                            inc files arent readable to everyone if u do it right... place the inc file in a specific directory... put an htaccess file in there requiring user authentication... then using curl you can retrieve the file by passing the correct login information

                            .htaccess

                            <files myclass.inc>
                            AuthType Basic
                            AuthName "Private"
                            AuthUserFile /usr/local/apache/passwd/passwords
                            Require user semtex
                            </files>
                            

                            something like that.. then use curl to access it.. nice and simple way to have it on one server

                            That's awesome. I assumed because all I could find was that remote includes were too insecure that a method as easy as this wouldn't work. Nice one!

                              gregsmith wrote:

                              Hi,
                              I'm also very interested in what other people use/do for build tracking. Are there any miniapps that manage this kind of thing? One that also manages ftp uploads would be the ultimate I guess! What takes the time is logging into each ftp area and uploading the files on 7 different servers (and growing).

                              Well, I would suggest you look at UE Studio (ultraedit.com). At $100 it's a snip.

                              I've been using ultraedit for 7 years now and love it. So if I needed the kind of vcs and multiple project build etc that you are talking about then I would start with UE Studio.

                                Roger Ramjet wrote:

                                Well, I would suggest you look at UE Studio (ultraedit.com). At $100 it's a snip.

                                I've been using ultraedit for 7 years now and love it. So if I needed the kind of vcs and multiple project build etc that you are talking about then I would start with UE Studio.

                                Thanks for the recommendation.

                                  scrupul0us wrote:

                                  inc files arent readable to everyone if u do it right... place the inc file in a specific directory... put an htaccess file in there requiring user authentication... then using curl you can retrieve the file by passing the correct login information

                                  .htaccess

                                  <files myclass.inc>
                                  AuthType Basic
                                  AuthName "Private"
                                  AuthUserFile /usr/local/apache/passwd/passwords
                                  Require user semtex
                                  </files>
                                  

                                  something like that.. then use curl to access it.. nice and simple way to have it on one server

                                  I've just tried using cURL including the .inc files (unprotected - haven't tried the htaccess bit yet) to echo php onto the page but it doesn't seem to get parsed as php.

                                  here's my cURL code:

                                  #start cURL include
                                  $ch = curl_init();
                                  $timeout = 5; // set to zero for no timeout
                                  curl_setopt ($ch, CURLOPT_URL, "http://www.site.com/includes/included_file.inc");
                                  curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
                                  curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
                                  $file_contents = curl_exec($ch);
                                  curl_close($ch);
                                  // display file
                                  echo $file_contents;
                                  #end cURL include

                                  Any ideas how to get it parsed AFTER the include but BEFORE output to the user?

                                    I've just answered my own question - found the eval() function in php.

                                      Write a Reply...