Connecting Tech Pros Worldwide Help | Site Map

Curious situation

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 02:15 PM
Shelly
Guest
 
Posts: n/a
Default 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("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, 02:15 PM
Geoff Berrow
Guest
 
Posts: n/a
Default 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, 02:16 PM
Shelly
Guest
 
Posts: n/a
Default 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, 02:16 PM
Shelly
Guest
 
Posts: n/a
Default 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]


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.