Re: sending variable to include file



vetchling wrote:
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.

Matt

You don't need to pass a variable to an included file, it already has access to all variables in the includING script. It becomes part of the script that is including it.

$page = 'Home';
include 'header.php';

Now header.php will see that $page contains 'Home'.

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
.



Relevant Pages

  • Re: sending variable to include file
    ... vetchling wrote: ... problem I can't fix, ... being nothing but an empty string. ...
    (comp.lang.php)
  • Re: sending variable to include file
    ... vetchling wrote: ... problem I can't fix, ... being nothing but an empty string. ... <?php function printHeader{?> ...
    (comp.lang.php)
  • lk-changelog.pl 0.167
    ... This script is used by Linus and Marcelo to rearrange and reformat BK ... fix obfuscation of unknown addresses in terse/oneline modes ... Bryan O'Sullivan's address got hosed. ... $indent is auto-generated from $indent1. ...
    (Linux-Kernel)
  • Re: Problem with popen on windows
    ... I just found a fix that works for me.. ... parent for the child script.. ... Private Function ParseCmdLine ... >> def system ...
    (comp.lang.ruby)
  • Re: Script-in SELF Permission?
    ... Im all set in the mailbox rights area, ... Using the script Quest gave me to fix the msExchangeSecurityDescriptor ... I need a script or app that will go into each user object ...
    (microsoft.public.windows.server.active_directory)