include

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

    include

    I have a php file which include() 's a file with variables, and a file with
    functions.

    so:

    <? include("../data/common.inc") ?>
    <? include("../data/functions.inc") ?>

    if in the php file i then call a function from the functions file, the
    function doesn't see what values the variables in common.inc are, although
    the php file does see the variable values.

    Is there a way of getting round this or is something just going really
    wrong?

    Thanks.


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003


  • Martijn van Schie

    #2
    Re: include

    Hi there
    The way you are including now, is that the server will pars this request
    and thereby giving you the RESULT of the .inc file.

    If you include with the full pathname (c:\root\to\fil e.inc) than the
    source of the inc file is included and not parsed via the server.
    In this way it's like the source of the inc file was in the source of the
    php file you include it in.

    That's what you want.
    Good Luck.


    ##-----------------------------------------------##
    Article posted from PHP Freaks NewsGroups

    Get Addicted: comp.lang.php
    ##-----------------------------------------------##

    Comment

    • 2metre

      #3
      Re: include


      "Martijn van Schie" <ma.van.schie_a t_wanadoo_dot_n l@foo.com> wrote in
      message news:4cycnfaQre 1Bj4iiXTWQkQ@gi ganews.com...[color=blue]
      > Hi there
      > The way you are including now, is that the server will pars this request
      > and thereby giving you the RESULT of the .inc file.
      >
      > If you include with the full pathname (c:\root\to\fil e.inc) than the
      > source of the inc file is included and not parsed via the server.
      > In this way it's like the source of the inc file was in the source of the
      > php file you include it in.[/color]

      Sorry but I think this is rubbish!

      Whether you use absolute addressing (c:\root\to\fil e.inc) or relative
      addressing ("../data/common.inc") makes absolutely no difference to the way
      PHP handles the included file contents!

      The contents of the include file are parsed exactly as if they had been
      written in place of the include statement.
      (either that or I am deeply troubled!!)


      Comment

      • Craig Bailey

        #4
        Re: include

        In article <bf37kk$2tc$1@h ercules.btinter net.com>,
        "2metre" <nws@hersham.ne t> wrote:
        [color=blue]
        > The contents of the include file are parsed exactly as if they had been
        > written in place of the include statement.
        > (either that or I am deeply troubled!!)[/color]

        I have a related problem.

        I'm trying to include a header on all pages on a site. The header
        contains JavaScript to build flyout buttons on the menu bar. (The code
        is pretty involved; it's generated for me by Dreamweaver.)

        Works fine when the file that's calling the include file is in the same
        directory as include file. But call the include from a subfolder, and
        none of the JavaScript magic works, because the relative links in the
        header include file are broken (I assume).

        Is there anyway to get around this, short of editing the header code by
        hand to try and turn all relative links into absolute links (like I
        said, the code's very dense) or short of placing every document on the
        site in the same folder as the include? (I'd also guess editing the
        header code by hand would make it forever uneditable by Dreamweaver,
        which is unacceptable, as the header files gonna change as the site
        grows.)

        --
        Floydian Slip(tm) - "Broadcasti ng from the dark side of the moon"
        Random Precision Productions(tm)
        67 Union St. #2D, Winooski, Vt. 05404-1948 USA
        Sundays, 7-8 pm - Champ 101.3 FM, Colchester; 102.1 FM, Randolph, Vt.
        ccb@floydiansli p.com - AIM: RandomPrec - www.floydianslip.com

        Comment

        • CC Zona

          #5
          Re: include

          In article <bf0oat$88$1@sp arta.btinternet .com>,
          "Jerz" <markjerz2@hotm ail.com> wrote:
          [color=blue]
          > I have a php file which include() 's a file with variables, and a file with
          > functions.
          >
          > so:
          >
          > <? include("../data/common.inc") ?>
          > <? include("../data/functions.inc") ?>
          >
          > if in the php file i then call a function from the functions file, the
          > function doesn't see what values the variables in common.inc are, although
          > the php file does see the variable values.[/color]

          Sounds like a scope issue. Are you referencing global vars correctly? See <http://php.net/language.variab les.scope>

          --
          CC

          Comment

          Working...