Jump to content

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;
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.