While I have never used fopen, I think a good start would be found here in the php manual: fopen().

There are examples further down the page.

Hope that helps out somewhat.

Cheers,

NRG

    The server I am on at work doesnt allow me to use the script ilz gave me it gives me this kind of message...

    Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in d:\websites\crcinfoca\html\english\index.php on line 104

    Warning: file_get_contents(http://www.crcinfo.ca/html/english/footer.php) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in d:\websites\crcinfoca\html\english\index.php on line 104

    So I am not quite sure where to go from here arent there other possibilities/.?

      Chrismichaelz wrote:

      Anyone got any solutions or have used fopens before?

      Did you try fopen() by using an example in the php manual? If so, what was the error message?
      example:

      $ticker = fopen("http://site.dotcom/ticker.php/", "r");
      echo $ticker;
      

      Cheers,

      NRG

        Chrismichaelz wrote:

        Anyone got any solutions or have used fopens before?

        Did you try fopen() by using an example in the php manual? If so, what was the error message?

        Cheers,

        NRG

          I would assume that allow_url_open is also disabled.

          Since this is a shared hosting machine, there isn't much you can do about it. Well, I'll give a suggestion later, but for now....

          1. Do you actually have php scripts on physically separate servers that depend on your updates.php script?

          2. Do you actually need to parse the php code in the updates.php script?

          Finally...

          Whats that all about?

          fopen opens a file pointer resource, it does not give you the file contents. You have to use functions such as fread() to read the file and return the contents.

            Well Yes I actually do need this because my site has many folders(directories) and theres over 800 pages I don't want to update them seperatley aswell I don't want them out of folders cause its organized. There must be a away to fix this issue without paying for a dedicated server cause it doesnt need one it doesnt exceed bandwidth ever.

            Edit...

            Everything is on the same server I just need to be able to include this file in many pages that are in many folders.

              Chrismichaelz wrote:

              Everything is on the same server I just need to be able to include this file in many pages that are in many folders.

              Bingo! You DO NOT need to use a url to get the updates.php include file! If you have one updates.php file, simply make a test.php (or whatever) file in that virtual root (same website as the updates.php folder) and do this...

              <?php
              echo $_SERVER['DOCUMENT_ROOT'];
              ?>
              

              That will give you the server path to your file.

              Next (this is only required if your websites reside in different virtual roots and have different owners), you'll need to make your updates.php file world readable (I have no idea if you have shell access, I will guess you have cpanel or something.) link

              Now, in all your include statements, you'll need to change to something like...

              <?php
              include("/path_from_test.php/updates.php");
              // or if all files are part of same website (same virtual root)
              include($_SERVER['DOCUMENT_ROOT'] . "/updates.php");
              ?>

                You kinda lost me do u have msn and maybe u cud walk me thru this

                  Sorry I really need to work now, but basically, since all your files are on the same server, you don't have to access them through http protocol. You can use a standard path for the include.

                  $_SERVER['DOCUMENT_ROOT']

                  is a built in PHP variable that gives you the path to your website from the server's perspective. If you have files that need access to the include for different websites, they will need to know the absolute path. In windows absolute vs relative path would be like:

                  Absolute Path: "c:\inetpub\mysite"

                  Relative Path "mysite\"

                  The absolute root for your server is "/" ("C:\" in windows.) The virtual root for your website (absolute root from your Web servers perspective) is http://yoursite/ Thus, your images, etc can use relative paths to open images "images/my.gif" Now, the absolute path from the server to your website may be something like "/var/www/html_docs/mysite"

                  So if you have a website in another folder

                  "/var/www/html_docs/anothersite"

                  To use the include file under a page in "anothersite", you'd need something like

                  include("/var/www/html_docs/mysite/updates.php");

                  Of course, if all PHP files are in the same virtual root "mysite", then you can just use

                  include($_SERVER['DOCUMENT_ROOT'] . "/mysite/updates.php");

                  Sorry, I can't make it more plain than that.

                  Good luck.

                    I'll try to expand on what bretticus said and provide another thing that might help.

                    You can put a file in the same directory as your updates.php that contains the following:

                    <?php
                    echo '<pre>';
                    echo $_SERVER['DOCUMENT_ROOT'];
                    echo $_SERVER['SCRIPT_FILENAME'];
                    echo '</pre>';
                    ?>
                    

                    Then you can compare the 2 and see what directories you need to place after the $_SERVER['DOCUMENT_ROOT'].

                    For example:

                    include($_SERVER['DOCUMENT_ROOT'] . "/PATH/DIFFERENCES/updates.php");
                    
                      Chrismichaelz wrote:

                      So this is just used to get my document paths?

                      Well, almost, the post I submitted Today 11:05 AM was an effort to help you discover the absolute path (directory path on your server) to your updates.php script. Illzz last post was an attempt to make it more clear how to go about that.

                      Here is the issue...we still don't know if all your php scripts that include updates.php reside under your website that you posted or if they reside under various websites (all on that same server of course.)

                      Scenario 1: ALL IN SAME WEBSITE (same virtual root)

                      In this case, the path to all your files will start with the same directory path to your website folder. (it might be /home/chrismichaelz/html_pub/yoursite for example.) In this case, any PHP script that runs anywhere in your website can get the path to the virtual root (/home/chrismichaelz/html_pub/yoursite) just by returning

                      $_SERVER['DOCUMENT_ROOT']

                      . Thus to get the proper path to your updates file, you can simply write all your include statements as...

                      include($_SERVER['DOCUMENT_ROOT'] . "/updates.php"); 

                      Scenario 2: SOME (OR ALL) IN DIFFERENT WEBSITES

                      In this case when you return the value for...

                      $_SERVER['DOCUMENT_ROOT']

                      you will get the directory path to the virtual root for the website in which your CURRENT PHP scripts reside. Consequently...

                      include($_SERVER['DOCUMENT_ROOT'] . "/updates.php"); 

                      will not be the proper path to that one include file you want to maintain.
                      In this case just write in the path to your one updates.php file...

                      include("/home/chrismichaelz/html_pub/updates.php"); 

                      . Since we (illzz and I) don't know what...

                      echo $_SERVER['DOCUMENT_ROOT'];

                      returns, it's up to you to figure out the directory path to your one file.

                      There's a good chance that updates.php is world readable (readable by any user on the server) by default. But if you get permission errors on the include, you may need to make it world readable.

                      More on navigating paths in *nix operating systems.

                      Good luck!

                        The file is only for one site on one server they arent included on any other site but my own. However this website is broken down into many sub folders due to its size and needs to be organized.

                          Chrismichaelz wrote:

                          The file is only for one site on one server they arent included on any other site but my own. However this website is broken down into many sub folders due to its size and needs to be organized.

                          Chris, this is starting to sound more and more like the permission rights set by whoever is hosting this .php file you seek is disallowing any form of access.

                          Perhaps you can contact whoever is hosting this file, and discuss what it is you are trying to do (show him/her your site) and see if they are willing to work with you on this?

                          -or-

                          ask if you can host that.php file on your webserver as well (which would then be very easy to include.. but you would have to update it yourself).

                          Other than that.. I'm rather stumped.

                          Cheers,

                          NRG

                          *edit.. just out of curiosity, which version of PHP is YOUR service provider using?
                          I was looking through the online php manual.. looking up include(), just to see if I was missing something.. and something did catch my eye:

                          Warning

                          Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if allow_url_fopen is enabled.

                          You can find this out easily by adding the following line in one of your online pages:

                          echo phpinfo();
                          

                            I am hosting the file. This is my site not any one elses. I am using only 1 server.

                            If you go to crcinfo.ca/html/test/index.php

                            I am still getting these errors for some reason...

                            Warning: main(/updates.php) [function.main]: failed to open stream: No such file or directory in d:\websites\crcinfoca\html\test\header.php on line 136

                            I use 2 servers. On one server it worked Betticus code.

                            I made the exact same site on another server at work and it didnt work...

                            <?php

                            include($_SERVER['DOCUMENT_ROOT'] . "/footer.php");
                            ?>

                            Any idea why ?

                              What does like 136 say in the header.php?

                              As for the other error what do you get when you echo $_SERVER['DOCUMENT_ROOT']??
                              Is footer.php in that directory or is it in a subdirectory?

                                Chrismichaelz wrote:

                                I am hosting the file. This is my site not any one elses. I am using only 1 server.
                                ...
                                I use 2 servers. On one server it worked Betticus code.

                                I made the exact same site on another server at work and it didnt work...

                                Any idea why ?

                                Sorry, you said just one server, and then you say two. I'm confused. You can never find a local file on a remote filesystem. If you do indeed need the updates.php file at work, you can just include it as usual over http (albeit slightly insecure.)