Jump to content

Recommended Posts

I am using:

 

header.php

index.php

footer.php

 

All in one instance. I need to get the variable $title from the index to echo in header. How do I get this to the header file. I tried simply:

 

echo $title; in the header, but it does not call it.

 

Thanks in advance!

Options

#1 create another file called global.php

<?php
$title = "My Title";
?>

then add

include "global.php";

at the start of header.php & index.php

 

#2 Store it in a session ie

<?php
start_session(); //at the top
$_SESSION['title'] =  $title;
?>

 

EDIT: PS this is one of those questions where it may help us if we know why you want!

All in one instance. I need to get the variable $title from the index to echo in header. How do I get this to the header file. I tried simply:

 

echo $title; in the header, but it does not call it.

 

Because that's entirely a different file which is obviously out of the scope.  Like MadTechie said you should store it in a session variable so you can easily pass it among pages.  This will avoid including files.

I just used a query in the header file and that did it.

 

You guys have been very helpful.

 

Thank you!

 

Hmm, not sure how that solved you problem because your question was (not really a question):

 

I need to get the variable $title from the index

 

In any event, glad you resolved everything.  :D

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.