Forum Moderators: coopster

Message Too Old, No Replies

Use HTTP query or Variable in PHP Includes?

         

JAB Creations

12:53 pm on Jan 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to pass a dynamic HTTP query. It's already set when this file itself is requested...I merely need to use it again when including a child file though my attempts haven't been fruitful. Here is one of my attempts...

- John

<?php
$getnameis = $_GET['nameis'];
if ($_COOKIE['counter']>2) {include realpath(dirname(__FILE__) . "/contact-email.php?nameis=".$getnameis);}
?>

[edited by: JAB_Creations at 12:54 pm (utc) on Jan. 2, 2008]

adb64

1:05 pm on Jan 2, 2008 (gmt 0)

10+ Year Member



Hi John,

You can't pass GET parameters to include files that way. But the global $_GET is also known in include files so in contact-email.php you can access $_GET['nameis'] in the same way as you do now. Also the global $getnameis is known by that name in contact-email.php.

Regards,
Arjan

whoisgregg

2:14 pm on Jan 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A working example of what adb64 describes... :)

file1.php:

<?php
$_GET['whatever'] = 'blue';
include('file2.php');
?>

file2.php:

<?php
echo $_GET['whatever']; // blue
?>

JAB Creations

5:01 pm on Jan 2, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just like a class variable but not a variable. The related issue has been resolved. :)

- John