Checking variables in an include

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

    #1

    Checking variables in an include

    Hi everybody,

    could anybody explain the following phenomen :

    I have this line in my project :

    include
    "http://".$domain."/help/".$language ."/".$defaultIndex ."/".$help.".p hp";

    This construct properly includes the file I need to. And the included
    file contains the following line :

    echo $domain;

    - and on this place comes nothing: obviously, the variable '$domain' is
    not set for the <help.php>.

    Why ?

    Regards

    Victor

  • Andy Hassall

    #2
    Re: Checking variables in an include

    On 6 Oct 2006 15:30:18 -0700, "Victor" <big.boss@chefm ail.dewrote:
    >could anybody explain the following phenomen :
    >
    >I have this line in my project :
    >
    >include
    >"http://".$domain."/help/".$language ."/".$defaultIndex ."/".$help.".p hp";
    >
    >This construct properly includes the file I need to. And the included
    >file contains the following line :
    >
    >echo $domain;
    >
    >- and on this place comes nothing: obviously, the variable '$domain' is
    >not set for the <help.php>.
    >
    >Why ?
    How are you expecting it to be set? You're (almost certainly) executing the
    remote PHP file in a totally different context - all you're include()ing is the
    output of the PHP file from the remote server.

    The only way it could work is if the webserver you're calling returns the PHP
    source verbatim, without processing it, in which case it's run in the same
    context as the calling script.

    Are you sure you want to be doing remote HTTP includes? Including from the
    filesystem is by far the more common usage, and is more likely to behave how
    you expect.

    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Victor

      #3
      Re: Checking variables in an include

      How are you expecting it to be set? You're (almost certainly) executing the
      remote PHP file in a totally different context - all you're include()ing is the
      output of the PHP file from the remote server.
      >
      The only way it could work is if the webserver you're calling returns the PHP
      source verbatim, without processing it, in which case it's run in the same
      context as the calling script.
      >
      Are you sure you want to be doing remote HTTP includes? Including from the
      filesystem is by far the more common usage, and is more likely to behave how
      you expect.
      >
      You see, the file I am including is not a remote one. It sits in my
      project directory. I agree, it might be not the best way to do
      includes, but this way it is easier for me, because I use rather many
      of them, calling them from different sublevels of the directory. And
      the file that makes the described include is also not the one that has
      set the variable $domain, but already 4th or something like this in the
      hierarchy of includes. Nevertheless, it sees the variable and
      constructs a correct name of the next include.
      Suddenly, this following include does not see the $domain any more...

      Victor

      Comment

      • Andy Hassall

        #4
        Re: Checking variables in an include

        On 6 Oct 2006 15:44:44 -0700, "Victor" <big.boss@chefm ail.dewrote:
        > Are you sure you want to be doing remote HTTP includes? Including from the
        >filesystem is by far the more common usage, and is more likely to behave how
        >you expect.
        >>
        >You see, the file I am including is not a remote one. It sits in my
        >project directory.
        So include it through the filesystem. By using an HTTP URL you are doing
        something completely different; reading the output of a completely separate
        instance of PHP.

        --
        Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
        http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

        Comment

        • Victor

          #5
          Re: Checking variables in an include


          Thanks Andy!

          I believe you have right... I'll try it and then report the result.

          Victor

          Comment

          • Victor

            #6
            Re: Checking variables in an include

            Yes, it works!

            Thank you once again Andy!

            Victor

            Comment

            Working...