Jump to content

[SOLVED] Get A Variable From A Current Page


monkeybidz

Recommended Posts

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

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.