Global Variables

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi. I am designing a page and want to use global variables, but I
can't quite get them to work. For example I have this:
<?php echo $title ?>
<?php require_once ("colophon.php") ?>
In the body of my page. In colophon.php I have the line
<?php $title="Title" ?>
I cannot access the variable though, even when I tried
<?php echo GLOBAL["title"] ?>

Can this be done? If so, how?


Re: Global Variables

On 4 Nov 2004 15:53:50 -0800, (Dante) wrote:

Quoted text here. Click to load it

 So you're require'ing the colophon.php file _after_ the first usage of $title?

 PHP is unable to travel back through time and affect statements already
executed :-) Require the include file _before_ you try and use its contents...

< Space: disk usage analysis tool

Re: Global Variables

if you're variables are in fields you can access them using POST or GET.

$var_post = $_POST['field_name'];
$var_post = $_GET['field_name'];

you could also use $_REQUEST['field_name'];

you could force it onto the query string, that's probably not great code
<a href=" test</a>
 $var = $_GET['field'];  // which would be var

i'm not sure if you can access the variables directly though.

Quoted text here. Click to load it

Site Timeline