Connecting Tech Pros Worldwide Forums | Help | Site Map

Curious situation

Shelly
Guest
 
Posts: n/a
#1: Jul 17 '05
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("decomp.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
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Curious situation


I noticed that Message-ID: <oq2dndVvafIpRETfRVn-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/
Shelly
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Curious situation


\"Geoff Berrow" <blthecat@ckdog.co.uk> wrote in message
news:8t6kd1565d7i3saln8tjhth9fm2prerhmn@4ax.com...[color=blue]
>I noticed that Message-ID: <oq2dndVvafIpRETfRVn-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("dbLoginStuff.php"); ?>

and the dbLoginStuff.php has

<?php stuff ?>

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

<?php <?php stuff ?> ?>

if it worked like other includes.

Thanks.

Shelly


Shelly
Guest
 
Posts: n/a
#4: Jul 17 '05

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:8t6kd1565d7i3saln8tjhth9fm2prerhmn@4ax.com...[color=green]
>>I noticed that Message-ID: <oq2dndVvafIpRETfRVn-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("dbLoginStuff.php"); ?>
>
> and the dbLoginStuff.php 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]


Closed Thread