Jump to content

[SOLVED] Passing a Variable to Another Page


dylandcor

Recommended Posts

I want to dynamically generate content based on where a user is in my site.  I set a variable $page in the index page before I included header.php with the following code in it.  The header.php cannot seem to find the $page variable.  Any help would be greatly appreciated.

index.php

<?php
$page="index";
include ("header.php);
?>

header.php

<?php
if ($page=="index"){
$html="<b>WELCOME TO THE INDEX";
$htmlsidebar="";
}else{
$html="<tr>";
echo $html;
?>

the concept of your code is fine...there are some syntax errors though

<?php
$page="index";
include ("header.php");
?>

<?php
if ($page=="index"){
   $html="<b>WELCOME TO THE INDEX";
   $htmlsidebar="";
}else{
   $html="<tr>";
}
echo $html;
?>

Thank you for your quick replies!  I have done what you both said and cleaned my code up.  It is still however... Not working.  I had the index echo the $page variable and it does do the correct one.

index.php

<?php
$page="index";
echo $page;
include ("http://www.mysite.com/header.php");
?>

I then have the header.php echo the $page variable which does not work.

header.php

<?php
if (!isset($page)) {
echo "DOES NOT EXIST";  #I am getting this when I load the page which proves that the variable does not exist?
}
#Start Content Here

if ($page=="index"){
$html="Index";
$htmlsidebar="";
}else{
$html="Other Site";
}

echo $page;
echo $html;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.