Re: sending variable to include file
- From: Andrew Poelstra <apoelstra@xxxxxxxxxx>
- Date: Fri, 18 Aug 2006 04:41:36 GMT
"vetchling" <vetchling@xxxxxxxxx> writes:
Hi, I'm pretty new to php but I've been working on a site and have a
problem I can't fix, though it's probably pretty simple.
Basically I have an index.php file that includes a header.php file. I
attempt to pass a variable to it as follows:
<?include("header.php?page=Home");?>
Then the header.php file contains this code:
<?php
$page = $_GET['page'];
?>
<html><head><title><?$page?></title>
I want $page to contain the string "Home" of course, but it ends up
being nothing but an empty string.
Thanks in advance for your help.
You can't add ?args to an include; PHP doesn't evalutate that when
including files. (In fact, it usually never evaluates URL arguments:
that's the HTTP daemon's job.) It merely copies the contents of
header.php directly into your document (or parses equivilantly).
To do this, you need to do:
#In mypage.php you need to access $mypage_page directly.
mypage_page = "Home";
include ("mypage.php");
I've prefixed the variable $page to avoid naming conflicts.
--
Andrew Poelstra <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
.
- References:
- sending variable to include file
- From: vetchling
- sending variable to include file
- Prev by Date: keystone php3 app log and pastebins trying get rid of errors on php 4.3.9 on redhat linux httpd 2.0.52
- Next by Date: $txt line
- Previous by thread: sending variable to include file
- Next by thread: Re: sending variable to include file
- Index(es):
Relevant Pages
|