For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > October 2007 > Re: Is it possible to pass a variable to a PHP script from inside another PHP piece o









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Is it possible to pass a variable to a PHP script from inside another PHP piece o
Rik Wasmus

2007-10-27, 7:01 pm

On Sat, 27 Oct 2007 23:44:56 +0200, leonardodiserpierodavinci@gmail.com =
=

<leonardodiserpierodavinci@gmail.com> wrote:

> Hi. Sorry for what is perhaps a neophyte question: is it possible to
> pass a variable to a PHP script from inside another PHP piece of code?=


>
> For instance, the file test.php (which of course resides on a
> webserver that supports PHP) is as such:
>
> [some HTML code...]
> <?php
> echo("<i>the variable abc contains " . $_GET['abc'] . "</i>");
> ?>
> [some more HTML code...]
>
> and if I open this file directly i.e. by typing test.php?abc=3D888 in
> the URL line of a web browser, I correctly get the message "the
> variable abc contains 888" in italic, surrounded by the HTML content.
>
> Now, let's say that I want to include all this content in another
> file, index.php.
> I tried to call it as such in index.php
>
> [other HTML...]
> <?php
> include "test.php?abc=3D888";
> ?>
> [yet other HTML...]
>
> which is not the correct way as it gives the following error:
>
> Warning: main(l/test.php?abc=3D888) [function.main]: failed to open
> stream: No such file or directory in /home/www/index.php on line 52
> Warning: main() [function.include]: Failed opening 'l/test.php?
> abc=3D888' for inclusion (include_path=3D'.:/usr/share/php:/usr/share/=


> pear') in /home/www/index.php on line 52
>
> How should I call the file?
> Thanks in advance for any hint!


The $_GET array is available to all scipts, _provided_ you use the file =
=

system to include the file, and not by http some newcomers seem to do. S=
o:

URL:
test.php?foo=3Dbar

test.php:
<?php
$check =3D 'hello';
include './include.php';
?>

include.php
<?php
var_dump($_GET);
echo $check;
?>

... will correctly show the $_GET array and the $check variable.
-- =

Rik Wasmus
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com