How to get url of current url from included script on different server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Venturer

    #1

    How to get url of current url from included script on different server

    I have a banner script that is included in php on a website but the
    actual script is hosted on a different site allowing me to only edit
    one file to update the script.

    I need to store in a variable the hostname that the included script is
    being run on NOT the master url where it is hosted.

    Everything I try gives the url of where the script is hosted and NOT
    the location of the page where it is being called from which is what I
    want as I need be able to tell the banner script not to show the banner
    for the site which is it on.

    tia

  • Oli Filth

    #2
    Re: How to get url of current url from included script on differentserver

    Venturer said the following on 10/01/2006 09:52:[color=blue]
    > I have a banner script that is included in php on a website but the
    > actual script is hosted on a different site allowing me to only edit
    > one file to update the script.
    >
    > I need to store in a variable the hostname that the included script is
    > being run on NOT the master url where it is hosted.[/color]

    I'm assuming you're include()-ing the script as something like:

    include("http://remote.server.e xample.com/script.php");

    Is the remote server set to execute PHP or not?

    * If it is, then script.php is being run on the remote server, not the
    local server, so you're actually include()-ing the *output* of
    script.php, not the PHP code itself. In which case, you will need to
    either pass the hostname in the request for script.php, e.g.:

    include("http://remote.server.e xample.com/script.php?host =http://local.example.c om/mainscript.php" );


    * If the remote server is not set to execute PHP, then script.php will
    be executed on the local server, so there should be no problem. However,
    this configuration is a potential security risk, as anyone can request
    script.php and see the code.


    --
    Oli

    Comment

    • Justin Koivisto

      #3
      Re: How to get url of current url from included script on differentserver

      Oli Filth wrote:[color=blue]
      > Venturer said the following on 10/01/2006 09:52:
      >[color=green]
      >> I have a banner script that is included in php on a website but the
      >> actual script is hosted on a different site allowing me to only edit
      >> one file to update the script.
      >>
      >> I need to store in a variable the hostname that the included script is
      >> being run on NOT the master url where it is hosted.[/color]
      >
      >
      > I'm assuming you're include()-ing the script as something like:
      >
      > include("http://remote.server.e xample.com/script.php");
      >
      > Is the remote server set to execute PHP or not?
      >
      > * If it is, then script.php is being run on the remote server, not the
      > local server, so you're actually include()-ing the *output* of
      > script.php, not the PHP code itself. In which case, you will need to
      > either pass the hostname in the request for script.php, e.g.:
      >
      > include("http://remote.server.e xample.com/script.php?host =http://local.example.c om/mainscript.php" );[/color]

      This is something that I have never done (include from another
      server/domain)...

      Out of curiosity, does the $_GET array actually get populated with
      values sent in this way for the remote script? When I want that
      behavior, I usually use something like curl to send the request and
      receive the output.



      I know that if you do something like:
      include 'myfile.php?var =val1';

      That php looks for a file with that exact name (which will not exist in
      most cases). Therefore in order to make that work (locally anyway),
      you'd need to set the variable before the file was included.

      --
      Justin Koivisto, ZCE - justin@koivi.co m

      Comment

      • Oli Filth

        #4
        Re: How to get url of current url from included script on differentserver

        Justin Koivisto said the following on 10/01/2006 14:57:[color=blue]
        > Oli Filth wrote:
        >[color=green]
        >>* If it is, then script.php is being run on the remote server, not the
        >>local server, so you're actually include()-ing the *output* of
        >>script.php, not the PHP code itself. In which case, you will need to
        >>either pass the hostname in the request for script.php, e.g.:
        >>
        >>include("http ://remote.server.e xample.com/script.php?host =http://local.example.c om/mainscript.php" );[/color]
        >
        > Out of curiosity, does the $_GET array actually get populated with
        > values sent in this way for the remote script?[/color]

        Yes. The receiving remote server doesn't care (or know) where the HTTP
        request for script.php came from, so it acts exactly as if someone had
        requested that URL from their browser.

        [color=blue]
        > I know that if you do something like:
        > include 'myfile.php?var =val1';
        >
        > That php looks for a file with that exact name (which will not exist in
        > most cases). Therefore in order to make that work (locally anyway),
        > you'd need to set the variable before the file was included.[/color]

        Well yes, because "?var=var1" is meaningless in a local filesystem.
        Setting the local variable works because both scripts are being run
        locally in the same PHP instance.

        If you do something like include("http://example.com/file.php?foo=ba r"),
        then PHP goes away and performs an HTTP request, where "?foo=bar" has
        meaning, i.e. a GET sub-string.



        --
        Oli

        Comment

        • Justin Koivisto

          #5
          Re: How to get url of current url from included script on differentserver

          Oli Filth wrote:[color=blue]
          > Justin Koivisto said the following on 10/01/2006 14:57:
          >[color=green]
          >> Oli Filth wrote:
          >>[color=darkred]
          >>> include("http://remote.server.e xample.com/script.php?host =http://local.example.c om/mainscript.php" );[/color]
          >>
          >> Out of curiosity, does the $_GET array actually get populated with
          >> values sent in this way for the remote script?[/color]
          >
          > Yes. The receiving remote server doesn't care (or know) where the HTTP
          > request for script.php came from, so it acts exactly as if someone had
          > requested that URL from their browser.[/color]

          I'll have to keep that in mind next time I consider using curl for a
          simple get request...
          [color=blue][color=green]
          >> I know that if you do something like:
          >> include 'myfile.php?var =val1';
          >>
          >> That php looks for a file with that exact name (which will not exist in
          >> most cases). Therefore in order to make that work (locally anyway),
          >> you'd need to set the variable before the file was included.[/color]
          >
          > Well yes, because "?var=var1" is meaningless in a local filesystem.
          > Setting the local variable works because both scripts are being run
          > locally in the same PHP instance.[/color]

          That's what I was trying to explain. When I first started php (many
          years ago), I learned that while experimenting with different things.
          One of these days I'll get my site together that I plan to use for
          articles and such like that. ;)

          --
          Justin Koivisto, ZCE - justin@koivi.co m

          Comment

          • Venturer

            #6
            Re: How to get url of current url from included script on different server

            ok i'll explain more...

            a script on www.master.com/script.php

            contains a list of items:

            1.com
            2.com
            3.com

            the script.php file is included in a page:



            as

            include("http://www.master.com/script.php");

            the script.php checks for the domain it is on (which should tell it its
            on www.2.com/index.php) and then makes sure it WONT display its own
            domain in the script.php list... eg it will show 1.com and 3.com but
            not 2.com

            Of course what happens is that the domain test comes back as saying its
            on http://www.master.com

            How else can I do this and not have to update 50 websites when I want
            to make a common change to one file?

            Comment

            • Oli Filth

              #7
              Re: How to get url of current url from included script on differentserver

              Venturer said the following on 10/01/2006 22:01:[color=blue]
              > ok i'll explain more...
              >
              > a script on www.master.com/script.php
              >
              > contains a list of items:
              >
              > 1.com
              > 2.com
              > 3.com
              >
              > the script.php file is included in a page:
              >
              > www.2.com/index.php
              >
              > as
              >
              > include("http://www.master.com/script.php");
              >
              > the script.php checks for the domain it is on (which should tell it its
              > on www.2.com/index.php) and then makes sure it WONT display its own
              > domain in the script.php list... eg it will show 1.com and 3.com but
              > not 2.com
              >
              > Of course what happens is that the domain test comes back as saying its
              > on http://www.master.com
              >
              > How else can I do this and not have to update 50 websites when I want
              > to make a common change to one file?[/color]

              Well, the easiest way is to pass a GET variable which contains the
              "local" URL when include()-ing http://www.master.com/script.php, as I
              suggested in response to your original post.

              However, we might be able to help more if you explain *why* you want to
              access a remote script in this way.


              P.S. "www.master.com " is a domain, whereas "http://www.master.com" and
              "http://www.master.com/script.php" are URLs.

              --
              Oli

              Comment

              • juglesh

                #8
                Re: How to get url of current url from included script on different server


                Venturer wrote:[color=blue]
                > include("http://www.master.com/script.php");
                >
                > the script.php checks for the domain it is on (which should tell it its
                > on www.2.com/index.php) and then makes sure it WONT display its own
                > domain in the script.php list... eg it will show 1.com and 3.com but
                > not 2.com
                >
                > Of course what happens is that the domain test comes back as saying its
                > on http://www.master.com
                >
                > How else can I do this and not have to update 50 websites when I want
                > to make a common change to one file?[/color]

                Ah, you might be looking for the "Non-Standard File Extension" Try

                include 'http://www.remotedomai n.com/script.xyz';
                this script should have open/close php tags.

                You can use the $_SERVER array in script.xyz as if it were on the
                includer domain. I use this all the time to put hit counter code, etc
                in my sites.

                Do be aware, anyone could browse to www.remotedomain.com/script.xyz and
                see the raw php code, so you shouldnt use this for anything secret.

                --
                juglesh

                Comment

                Working...