Simple PHP Include Question... Help Please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheSquealer
    Mayor of Thneedville
    • Oct 2004
    • 26174

    #1

    Simple PHP Include Question... Help Please

    in this file:
    http://www.domain-one.com/folderone/...lename-one.php

    I want to use PHP to include a file located here:
    http://www.domain-two.com/folderone/...lename-two.php

    I can't seem to get it to work.

    I've been looking around for answers and there seems to be a few different ways to do it and I can't get any to work

    Help!?
    .
    Yes, fewer illegal immigrants working equates to more job opportunities for American citizens.

    Rochard
  • SmokeyTheBear
    ►SouthOfHeaven
    • Jun 2004
    • 28609

    #2
    Originally posted by TheSquealer
    in this file:
    http://www.domain-one.com/folderone/...lename-one.php

    I want to use PHP to include a file located here:
    http://www.domain-two.com/folderone/...lename-two.php

    I can't seem to get it to work.

    I've been looking around for answers and there seems to be a few different ways to do it and I can't get any to work

    Help!?
    <?@readfile("http://www.domain-two.com/folderone/foldertwo/filename-two.php");?>
    hatisblack at yahoo.com

    Comment

    • cam_girls
      So Fucking Banned
      • Apr 2009
      • 2968

      #3
      I can't see the files,

      but the file you read in should just be some functions, no < H T M L > or < ? p h p

      just like you copied and pasted it into the main file.

      include 'http://site.com/secondfile.php'

      should work!

      Do a test, copy the 2nd file into your main file - same error message?

      Comment

      • sarettah
        see you later, I'm gone
        • Oct 2002
        • 14298

        #4
        Originally posted by TheSquealer
        in this file:
        http://www.domain-one.com/folderone/...lename-one.php

        I want to use PHP to include a file located here:
        http://www.domain-two.com/folderone/...lename-two.php

        I can't seem to get it to work.

        I've been looking around for answers and there seems to be a few different ways to do it and I can't get any to work

        Help!?
        Are the domains on the same server or different servers? Also, Nix or Win?

        If they are on the same server then include the file from domain 2 using the full path to the file, not the url.

        If they are not on the same server then if you are on win you cannot use include to pull it in, if you are on nix you can use include using the url if allow_url_include is set to true in your php.ini file.


        .
        All cookies cleared!

        Comment

        • SmokeyTheBear
          ►SouthOfHeaven
          • Jun 2004
          • 28609

          #5
          Originally posted by cam_girls
          I can't see the files,

          but the file you read in should just be some functions, no < H T M L > or < ? p h p

          just like you copied and pasted it into the main file.

          include 'http://site.com/secondfile.php'

          should work!

          Do a test, copy the 2nd file into your main file - same error message?
          huh ?....
          hatisblack at yahoo.com

          Comment

          • Babaganoosh
            ♥♥♥ Likes Hugs ♥♥♥
            • Nov 2001
            • 15841

            #6
            If allow_url_fopen is disabled on your server you won't be able to do it in php.
            I like pie.

            Comment

            • SmokeyTheBear
              ►SouthOfHeaven
              • Jun 2004
              • 28609

              #7
              <?php
              $curl_handle=curl_init();
              curl_setopt($curl_handle,CURLOPT_URL,'http://example.com/folder/file.html');
              curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1) ;
              $buffer = curl_exec($curl_handle);
              curl_close($curl_handle);
              echo $buffer;
              ?>
              hatisblack at yahoo.com

              Comment

              • raymor
                Confirmed User
                • Oct 2002
                • 3745

                #8
                Originally posted by sarettah
                If they are on the same server then include the file from domain 2 using the full path to the file, not the url.
                Do that. If using the URL works, your server admin fucked up and if the server had been live for more than 48 hours it's probably hacked by now.

                Code:
                <?@readfile("http://www.domain-two.com/folderone/foldertwo/filename-two.php");?>
                That's about par for the course with PHP code - three errors in one line. Do not use that.
                For historical display only. This information is not current:
                support&#64;bettercgi.com ICQ 7208627
                Strongbox - The next generation in site security
                Throttlebox - The next generation in bandwidth control
                Clonebox - Backup and disaster recovery on steroids

                Comment

                • SmokeyTheBear
                  ►SouthOfHeaven
                  • Jun 2004
                  • 28609

                  #9
                  at the very least post something. my suggestions both work.. what you have posted does not
                  hatisblack at yahoo.com

                  Comment

                  • raymor
                    Confirmed User
                    • Oct 2002
                    • 3745

                    #10
                    Originally posted by sarettah
                    Are the domains on the same server or different servers? Also, Nix or Win?

                    If they are on the same server then include the file from domain 2 using the full path to the file, not the url.
                    Do that. Use the path, not the URL. Full path or relative path is OK.
                    The relative path is less likely to break when you move servers.

                    if you are on nix you can use include using the url if allow_url_include is set to true in your php.ini file.
                    allow_url_include requires allow_url_fopen.
                    allow_url_fopen requires stupid.
                    Therefore include(url) requires being stupid.

                    Use SmokeyTheBear's cURL code if they are on different servers. Be aware that's not like a PHP include, as you're getting the OUTPUT of the remote PHP script, not it's contents.


                    Originally posted by SmokeyTheBear
                    <?@readfile("http://www.domain-two.com/folderone/foldertwo/filename-two.php");?>
                    Smokey was right on the cURL code, but this line is typical for PHP code. Typical because it has three errors in one line of code.
                    For historical display only. This information is not current:
                    support&#64;bettercgi.com ICQ 7208627
                    Strongbox - The next generation in site security
                    Throttlebox - The next generation in bandwidth control
                    Clonebox - Backup and disaster recovery on steroids

                    Comment

                    • raymor
                      Confirmed User
                      • Oct 2002
                      • 3745

                      #11
                      Originally posted by SmokeyTheBear
                      at the very least post something. my suggestions both work.. what you have posted does not
                      My post was submitted before it was complete. Sorry about that. I meant to at least acknowledge that your cURL code looks good (though I didn't heavily analyze it).
                      For historical display only. This information is not current:
                      support&#64;bettercgi.com ICQ 7208627
                      Strongbox - The next generation in site security
                      Throttlebox - The next generation in bandwidth control
                      Clonebox - Backup and disaster recovery on steroids

                      Comment

                      • raymor
                        Confirmed User
                        • Oct 2002
                        • 3745

                        #12
                        Btw be very, very careful if there are any variables in the path or especially a URL. The bad guys can be very tricky about sneaking stuff into variables so you end up executing whatever they put at http://hacker.com/yourfucked.php?you.com/yourscript.php

                        Also you said "it doesn't work". What does the error log tell you about WHY it didn't work? When you say "it doesn't work", the second half of that sentence is the important part - it doesn't work and the error log says that's because ...

                        The very important message in the error log assumes you don't prefix the statement with "@" as you sometimes see people do. "@" means "when this fails don't tell me why and don't stop processing, just keep going as pretending it worked, without telling me what's wrong". It could be useful if you know that the statement is SUPPOSED to fail sometimes.
                        Last edited by raymor; 12-03-2011, 06:36 PM.
                        For historical display only. This information is not current:
                        support&#64;bettercgi.com ICQ 7208627
                        Strongbox - The next generation in site security
                        Throttlebox - The next generation in bandwidth control
                        Clonebox - Backup and disaster recovery on steroids

                        Comment

                        • sarettah
                          see you later, I'm gone
                          • Oct 2002
                          • 14298

                          #13
                          Originally posted by raymor
                          allow_url_include requires allow_url_fopen.
                          allow_url_fopen requires stupid.
                          Therefore include(url) requires being stupid.

                          Use SmokeyTheBear's cURL code if they are on different servers. Be aware that's not like a PHP include, as you're getting the OUTPUT of the remote PHP script, not it's contents.
                          I was only trying to tell the guy where his issue may lie, not making reccomendations.

                          Myself, unless I have control of the file I am pulling in, or it is on an extremely trusted site, I'm not pulling it in or pushing it out.

                          If I had this issue, on 2 different servers, with domains I control, I would probably just duplicate the file from server 1 on server 2. If the file was dynamic then I would use a curl solution like Smokey's.

                          but that just me.
                          All cookies cleared!

                          Comment

                          • cam_girls
                            So Fucking Banned
                            • Apr 2009
                            • 2968

                            #14
                            Originally posted by SmokeyTheBear
                            <?php
                            $curl_handle=curl_init();
                            curl_setopt($curl_handle,CURLOPT_URL,'http://example.com/folder/file.html');
                            curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1) ;
                            $buffer = curl_exec($curl_handle);
                            curl_close($curl_handle);
                            echo $buffer;
                            ?>

                            Smokey can you help me with a script that uses $curl to send an XML request with POST?

                            I need to read the XML stats and populate my Aff Program tables.

                            Comment

                            • sarettah
                              see you later, I'm gone
                              • Oct 2002
                              • 14298

                              #15
                              Originally posted by cam_girls
                              Smokey can you help me with a script that uses $curl to send an XML request with POST?

                              I need to read the XML stats and populate my Aff Program tables.
                              add curlopt_post and the curlopt_postfields to what smokey did.

                              curl_setopt($curl_handle, CURLOPT_POST, 1);
                              curl_setopt($curl_handle, CURLOPT_POSTFIELDS,"var=whatever&var1=whatever&var 2=whatever);
                              All cookies cleared!

                              Comment

                              • SmokeyTheBear
                                ►SouthOfHeaven
                                • Jun 2004
                                • 28609

                                #16
                                Originally posted by cam_girls
                                Smokey can you help me with a script that uses $curl to send an XML request with POST?

                                I need to read the XML stats and populate my Aff Program tables.
                                icq me or post variables and xml url
                                hatisblack at yahoo.com

                                Comment

                                • raymor
                                  Confirmed User
                                  • Oct 2002
                                  • 3745

                                  #17
                                  Originally posted by sarettah
                                  I was only trying to tell the guy where his issue may lie, not making reccomendations.

                                  Myself, unless I have control of the file I am pulling in, or it is on an extremely trusted site, I'm not pulling it in or pushing it out.

                                  If I had this issue, on 2 different servers, with domains I control, I would probably just duplicate the file from server 1 on server 2. If the file was dynamic then I would use a curl solution like Smokey's.

                                  but that just me.
                                  :

                                  Since I've called allow_fopen_url "stupid", I should acknowledge that I've written stupid code. A lot of what I've learned I didn't learn from a book, but from doing stupid. Heck, most of what I write wouldn't make it into the kernel, Linus would call it stupid. So my comment is only that the function should be avoided and shouldn't be interpreted as a slam on PEOPLE who use it.
                                  Last edited by raymor; 12-03-2011, 08:00 PM.
                                  For historical display only. This information is not current:
                                  support&#64;bettercgi.com ICQ 7208627
                                  Strongbox - The next generation in site security
                                  Throttlebox - The next generation in bandwidth control
                                  Clonebox - Backup and disaster recovery on steroids

                                  Comment

                                  • cam_girls
                                    So Fucking Banned
                                    • Apr 2009
                                    • 2968

                                    #18
                                    Originally posted by SmokeyTheBear
                                    icq me or post variables and xml url

                                    Thanks! I'm setting up the server today so I'll get what I can on there first so you can have a look.

                                    Comment

                                    • sarettah
                                      see you later, I'm gone
                                      • Oct 2002
                                      • 14298

                                      #19
                                      Know what I love about threads like this?

                                      Guy comes in and asks a question.

                                      4 different programmers and cam_girls come in and offer up solutions, reccomendations and what not and there is no trace of the original poster.

                                      Glad cam_girls got his hook up with smokey though. At least someone got something from the conversation.

                                      Makes ya wonder, ya know?



                                      .
                                      All cookies cleared!

                                      Comment

                                      • redwhiteandblue
                                        Bollocks
                                        • Jun 2007
                                        • 2793

                                        #20
                                        I bet none of the above solutions will work anyway because the OP probably wants to include the source file not the output file.
                                        Interserver unmanaged AMD Ryzen servers from $73.00

                                        Comment

                                        • TheSquealer
                                          Mayor of Thneedville
                                          • Oct 2004
                                          • 26174

                                          #21
                                          I want to thank everyone for their suggestions. I am going to keep playing with this today and try all the solutions. I know there are security concerns as well, which adds a bit to the mind fuck of what I thought was a simple thing.
                                          .
                                          Yes, fewer illegal immigrants working equates to more job opportunities for American citizens.

                                          Rochard

                                          Comment

                                          • TheSquealer
                                            Mayor of Thneedville
                                            • Oct 2004
                                            • 26174

                                            #22
                                            <?@readfile("http://www.domain-two.com/folderone/foldertwo/filename-two.php");?>
                                            Is there a reason not to do this? What are the errors?

                                            It works anyway.
                                            .
                                            Yes, fewer illegal immigrants working equates to more job opportunities for American citizens.

                                            Rochard

                                            Comment

                                            • u-Bob
                                              there's no $$$ in porn
                                              • Jul 2005
                                              • 33063

                                              #23
                                              Originally posted by TheSquealer
                                              Is there a reason not to do this? What are the errors?

                                              It works anyway.
                                              Short open tags don't work on all servers (got to set short_open_tag to On in php.ini) so the script isn't as portable as it should be (might dump php code to the surfers browser...)
                                              Using php short tags can also cause problems when using xml directives.

                                              Comment

                                              • SmokeyTheBear
                                                ►SouthOfHeaven
                                                • Jun 2004
                                                • 28609

                                                #24
                                                Originally posted by TheSquealer
                                                Is there a reason not to do this? What are the errors?

                                                It works anyway.
                                                grammatical errors. i made it simple. it works , there are no security concerns.
                                                hatisblack at yahoo.com

                                                Comment

                                                • cam_girls
                                                  So Fucking Banned
                                                  • Apr 2009
                                                  • 2968

                                                  #25
                                                  Originally posted by SmokeyTheBear
                                                  icq me or post variables and xml url
                                                  I found a script to send a XML POST request but this is all it does.

                                                  http://camaffiliate.com/chron_get_xml_2.php
                                                  400 Bad Request


                                                  http://camaffiliate.com/chron_get_xml_2.txt

                                                  Can you see the problem?

                                                  Comment

                                                  Working...