RE: [PHP] passing GET via include
| From: | Edward Kay | Date: | Fri, 04 May 2007 09:17:06 +0000 |
| Subject: | RE: [PHP] passing GET via include | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-254393@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Mark Smith [mailto:mark@lpstemp.dyndns.org]
> Sent: 04 May 2007 08:23
> Hello all,
> Is there a way to allow the passing of variables to included scripts
> using the GET method, for example include"file.php?name=person"; or is
> there another method of including files that allow you to do this. I
> have attempted to do this without success, I just get a message saying
> the file cannot be found.
>
Hi Mark,
No, this isn't possible as it makes no sense. When you include a file, you
are not performing a request that generates a response - you are simply
including the contents of one file in another. When you call include, think
of it as just copy/pasting the contents of the included file at that point.
Any variables already defined (and in scope) will therefore be be available
to the code included file, for example:
--- main.php ---
$strTitle = 'The title';
$intTitleLength = strlen($strTitle);
include('display.php');
--- display.php ---
echo 'Title is '.$strTitle.' and is '.$intTitleLength.' characters
long';
I hope this makes sense but feel free to reply to the list if you have any
questions.
Edward