Include Using Parent Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Include Using Parent Variables

Post by AliasBDI »

I have two pages. Page1 includes Page2. Page1 is being called to a frame by a URL that contains a query string ("/page1.php?var=foo"). Page2 is supposed to use this string variable in its execution. So Page2 has code which reads:

Code: Select all

$getVAR = $_REQUEST['var']; echo $getVAR;
Nothing appears. I also tried this by creating session variables in Page1. Any ideas on this? Should this even work?
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

if you include a page it should contain the var already in this case try $_SERVER['QUERY_STRING']
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post by AliasBDI »

If I use session variables, should I have session_start(); at the beginnig of each page and the page includes as well? OR do I just need one on the parent page?
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post by AliasBDI »

Maybe there is something wrong in my code. Can you check?

Page1:

Code: Select all

<?php
session_start();
include("../../../_common/incCOMMON.php");
include("../../../_common/incNOCACHE.php");
?>
<link href="<?php echo conSITEURL.conECTEMPLATEPATH; ?>/css/main.css" rel="stylesheet" media="all">
<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr align="left" valign="middle">
		<td width="20" background="<?php echo conSITEURL.conECTEMPLATEPATH; ?>/graphics/main/midbg.jpg"><img src="<?php echo conSITEURL.conECTEMPLATEPATH; ?>/graphics/main/midbg.jpg" width="20" height="43"></td>
		<td background="<?php echo conSITEURL.conECTEMPLATEPATH; ?>/graphics/main/midbg.jpg">
			<table border="0" cellspacing="0" cellpadding="2">
				<tr>
					<td><span class="areaTITLE"><span class="capitolize"><b><?php include_once(conSITEURL.conECTEMPLATEPATH.'/get/getAREA.php'); ?></b></span></span></td>
					<td><span class="areaTITLE"><span class="capitolize"><b><?php //include_once(conSITEURL.conECTEMPLATEPATH.'/get/getSUBAREA.php'); ?></b></span></span></td>
					<td><?php //include_once(conSITEURL.conECTEMPLATEPATH.'/get/getACTION.php'); ?></td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</body>
Page2 (getAREA.php):

Code: Select all

<?php
session_start();
include("../../../_common/incCOMMON.php");
include("../../../_common/incNOCACHE.php");

// CREATING THE AREA TITLE
$getAREA = $_REQUEST['getAREA'];
echo $getAREA;
if (empty($getAREA) || $getAREA="home"){
	$getAREA = conSITENAME." Management";
	echo "</span></span><font color=\"#FFFFFF\" class=\"areaTITLE\"><b>".$getAREA."</b></font><span class=\"capitolize\">";
} else {
	$_SESSION['getAREA'] = $getAREA;
	echo "<a href=\"".conECTEMPLATEPATH."/ec".$getAREA.".asp\" target=\"content\" onClick=\"top.frames['subheader'].location.href='".$getAREA."/frames/subheader.asp?getAREA=".$getAREA."'\" class=\"areaTITLE\"><b>".$getAREA."</b></a>";
}
?>
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Stick a

Code: Select all

print_r($_GET);
in page 2, right before you are assigning the variable in question, also try sticking this right before the include on page 1
Post Reply