sherry wrote:

If you think of a creative way to extract this info, please let me know.

Well, other than include()'ing the file locally, you could possibly try a workaround...

Instead of having the include()'ed script output data directly, store all output into a variable and return that variable rather than outputting it directly. That way, in the parent script, you could search for placeholders such as {BROWSER_NAME} and replace it with the contents of get_browser().

    bradgrafelman;10922827 wrote:

    Well, other than include()'ing the file locally, you could possibly try a workaround...

    Instead of having the include()'ed script output data directly, store all output into a variable and return that variable rather than outputting it directly. That way, in the parent script, you could search for placeholders such as {BROWSER_NAME} and replace it with the contents of get_browser().

    Thanks bradgrafelman - sounds doable to me!

    Now for the meat and potatoes question:

    What is an example statement or routine to do this - to replace the include() statement?

    Thanks.

      Not sure what you're asking... here's a brief example/outline of what I was referring to:

      EDIT: I'm an idiot. I forgot that the whole problem here was that you're including across HTTP. In order to do this, you'd actually have to use some output buffering (e.g. enable output buffering, include the remote file, grab & clear the output buffer's contents, str_replace() '{BROWSER_NAME}' with the correct data, and then re-output the correct data).

      Note that another option would be to send the user-agent string to the included script via the query string, e.g.

      include('http://mysite.com/include_me.php?agent=' . urlencode($_SERVER['HTTP_USER_AGENT']));

      In the included script, you would then use the agent string passed via the query string as the first parameter for the [man]get_browser/man function.

      EDIT2: Also note that since you're getting the data across HTTP, there's really no reason to use include() at all - a simple [man]file_get_contents/man or [man]readfile/man would suffice instead.

        Wow bradgrafelman - adding the query string to include() is so logical! Man, you're smart!

        For EDIT2, that was the route I was thinking as I was replying to (and based on) your last reply. At least you've confirmed to me that the option is worth taking a look at.

        Let me sleep on this to determine between the two, which one to go with. I really like them both! I wouldn't think there would be much overhead involved with either.

        I'll let you know once I have it working. 🙂

        Thanks so very much!

          Hello again.

          index.php (latest code version in place of include() statement):

          $agent = $_SERVER['HTTP_USER_AGENT'];
          $browser = get_browser($agent,true);
          $Browser = $browser['browser'];
          $get_file_content = file_get_contents('http://www...');
          echo $get_file_content;
          

          Within the echo'd code, it contains a block module which has the following:

          <?php
          if ( isset($Browser) ) 
          {
            echo '<font color="red" size="8">Browser:  ' . $Browser . '</font>';
          }
          ?>

          Q: How to get the value of $Browser BEFORE the 'echo' statement to satisfy the isset($Browser) condition statement that is contained within the echo'd code? 😕

          I'd venture to guess that using

          include('http://mysite.com/include_me.php?agent=' . urlencode($_SERVER['HTTP_USER_AGENT']));

          from bradgrafelman's last reply is the easiest way to go - I just want to at least try the other method.

          Thanks.

            You could use a place holder, e.g. {BROWSER_NAME} in the included file. Then, in the index (where the browser is known), just do a simple [man]str_replace/man after you retrieve the data.

              bradgrafelman;10922903 wrote:

              You could use a place holder, e.g. {BROWSER_NAME} in the included file. Then, in the index (where the browser is known), just do a simple [man]str_replace/man after you retrieve the data.

              That substitution works fine, bradgrafelman. I only have left to work out the conditional statement which I'll attempt later today.

              Q: How come the method I showed in my reply just before your last reply didn't work? Since the variable $Browser was set before the file_get_contents() statement , it would seem that the same variable found below its definition would take on that defined value in all applicable statements thereafter e.g. even upon echo'ing the file contents in $get_file_content. Why would the str_replace() method have to be used instead?

              Thanks.

                sherry wrote:

                Since the variable $Browser was set before the file_get_contents() statement , it would seem that the same variable found below its definition would take on that defined value in all applicable statements thereafter e.g. even upon echo'ing the file contents in $get_file_content. Why would the str_replace() method have to be used instead?

                Once again, it's because you're include()'ing over HTTP instead of via the local file system.

                Because you're including over HTTP, the webserver has to make a separate HTTP request (yes, to itself). The include()'ed file therefore has no knowledge or connection to the page the user is viewing (e.g. where $Browser is defined).

                  Ohhh... I got it now, bradgrafelman.

                  I hope to get back on this today or tomorrow so I can finish up this segment of coding. I couldn't work on it since my last reply as I had thought. Knowing what you just explained really helps create a clearer path for trying both methods. I'll report back here then.

                  Thanks as usual. 🙂

                    7 days later

                    Hi again.

                    Here is the update.

                    I figured out the 'if' statement although I had to change the template as it seemed like it was going to be too buggy to deal with going forward.

                    I've learned a lot here and know I have many more uses for this in the future.

                    Thanks again, bradgrafelman and everyone!

                      Also, you could just use curl to get the target file (in place of file get contents) and set the header for browser to whatever it detected from the initial request, basically forwarding the header along. then it would be as if the browser had requested the file, not the php script, so far as the target included script was concerned.

                        CoderDan;10923957 wrote:

                        Also, you could just use curl to get the target file (in place of file get contents) and set the header for browser to whatever it detected from the initial request, basically forwarding the header along. then it would be as if the browser had requested the file, not the php script, so far as the target included script was concerned.

                        Hi CoderDan. Thanks for your reply.

                        Although I haven't attempted curl yet, what you describe seems quite interesting and something I'd like to try in the future. I revisit this when I get to that point.

                        Again, thanks for the info.

                          Write a Reply...