Curious situation

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

    Curious situation

    I set a few session variables in a.php where each of the session variables
    is an array of the same size and call b,php. In b.php I get new arrays from
    those session variables. I then echoed the contents of the arrays in a
    loop. This works fine.

    Now, I went to do a require_once where I put the decomposition of the
    session variables into an include file and just included that file in b.php
    instead of explicitly have those lines there in b.php. The result was the
    set of php statements in the include file followed by the contents of the
    arrays.

    Why do the php code lines show up in the output?

    An example of what I am talking about is shown below.

    Shelly

    First b.php:
    ------------
    $num = $_SESSION['num'];
    $var1 = $_SESSION['var1'];

    for ($i=0; $i<$num; $i++) {
    echo $var1[$i] . "<br>";
    }
    ===============
    Second b.php
    ---------------
    require_once("d ecomp.inc");
    for ($i=0; $i<$num; $i++) {
    echo $var1[$i] . "<br>";
    }

    decomp.inc
    -------------
    $num = $_SESSION['num'];
    $var1 = $_SESSION['var1'];
    =============== =============
    First output:
    -------------
    value1
    value2
    =============== ==============
    Second output:
    -----------------
    $num = $_SESSION['num'];$var1 = $_SESSION['var1'];
    value1
    value2
    =============== =============== =


  • Geoff Berrow

    #2
    Re: Curious situation

    I noticed that Message-ID: <oq2dndVvafIpRE TfRVn-og@comcast.com> from
    Shelly contained the following:
    [color=blue]
    >Why do the php code lines show up in the output?[/color]

    At a guess you haven't put <?php and ?> around the code in decomp.inc

    When doing an include or a require you effectively drop out of php. So
    what you really have is:

    ?>
    $num = $_SESSION['num'];
    $var1 = $_SESSION['var1'];
    <?php

    hence the code is simply treated as plain html

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • Shelly

      #3
      Re: Curious situation

      \"Geoff Berrow" <blthecat@ckdog .co.uk> wrote in message
      news:8t6kd1565d 7i3saln8tjhth9f m2prerhmn@4ax.c om...[color=blue]
      >I noticed that Message-ID: <oq2dndVvafIpRE TfRVn-og@comcast.com> from
      > Shelly contained the following:
      >[color=green]
      >>Why do the php code lines show up in the output?[/color]
      >
      > At a guess you haven't put <?php and ?> around the code in decomp.inc
      >
      > When doing an include or a require you effectively drop out of php. So
      > what you really have is:
      >
      > ?>
      > $num = $_SESSION['num'];
      > $var1 = $_SESSION['var1'];
      > <?php
      >
      > hence the code is simply treated as plain html[/color]

      Makes sense. No, I didn't because I thought includes worked the way they do
      in C, C++, Java, etc. Looking at the my other include for db stuff (that
      was set up in Connections in Dreamweaver) it has the bracketing. What is
      interesting is I use that code as:

      <?php require_once("d bLoginStuff.php "); ?>

      and the dbLoginStuff.ph p has

      <?php stuff ?>

      I didn't notice this before, but this would give

      <?php <?php stuff ?> ?>

      if it worked like other includes.

      Thanks.

      Shelly


      Comment

      • Shelly

        #4
        Re: Curious situation

        That worked. Thanks.

        Shelly

        "Shelly" <sheldonlg.news @asap-consult.com> wrote in message
        news:UICdnSJov_ 1L3UffRVn-rA@comcast.com. ..[color=blue]
        > \"Geoff Berrow" <blthecat@ckdog .co.uk> wrote in message
        > news:8t6kd1565d 7i3saln8tjhth9f m2prerhmn@4ax.c om...[color=green]
        >>I noticed that Message-ID: <oq2dndVvafIpRE TfRVn-og@comcast.com> from
        >> Shelly contained the following:
        >>[color=darkred]
        >>>Why do the php code lines show up in the output?[/color]
        >>
        >> At a guess you haven't put <?php and ?> around the code in decomp.inc
        >>
        >> When doing an include or a require you effectively drop out of php. So
        >> what you really have is:
        >>
        >> ?>
        >> $num = $_SESSION['num'];
        >> $var1 = $_SESSION['var1'];
        >> <?php
        >>
        >> hence the code is simply treated as plain html[/color]
        >
        > Makes sense. No, I didn't because I thought includes worked the way they
        > do in C, C++, Java, etc. Looking at the my other include for db stuff
        > (that was set up in Connections in Dreamweaver) it has the bracketing.
        > What is interesting is I use that code as:
        >
        > <?php require_once("d bLoginStuff.php "); ?>
        >
        > and the dbLoginStuff.ph p has
        >
        > <?php stuff ?>
        >
        > I didn't notice this before, but this would give
        >
        > <?php <?php stuff ?> ?>
        >
        > if it worked like other includes.
        >
        > Thanks.
        >
        > Shelly
        >[/color]


        Comment

        Working...