Connecting Tech Pros Worldwide Help | Site Map

Curious situation

  #1  
Old July 17th, 2005, 03:15 PM
Shelly
Guest
 
Posts: n/a
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
===============================


  #2  
Old July 17th, 2005, 03:15 PM
Geoff Berrow
Guest
 
Posts: n/a

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/
  #3  
Old July 17th, 2005, 03:16 PM
Shelly
Guest
 
Posts: n/a

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


  #4  
Old July 17th, 2005, 03:16 PM
Shelly
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Curious IE "feature" titch answers 1 November 12th, 2006 12:14 AM
py2exe: abnormal program termination PyDenis answers 16 March 15th, 2006 04:45 PM
Origin of size_t? Curious. Confused User answers 40 November 15th, 2005 12:09 AM
curious about command buttons Stu answers 5 November 13th, 2005 01:22 PM