[help] php global variables question

so here I am again trying to figure out how the hell global variables work, and I am wondering what I am doing wrong. someone kindly give me some guidance!

I'm trying to change the title of the page when the content reloads. I'm trying to do this through a global variable in the title section below.

here is my code so far:

<title>

UITS Web Hosting Services - <?php global $page_title; if (!isset($_GET['active_page'])) /* if page title IS NOT set through GET, then echo default title */ { echo"Home Page and Informationn"; } else /* page_title is set through GET */ { echo"$page_titlen"; } ?>

</title>

and in the main program

$active_page = $_GET['active_page'];

global $page_title;

$page_title = m00;

echo"page title is: '{$GLOBALS['page_title']}' - blahh";



if ($active_page == 'index')

{

include ('site_content/index_content.htm');

$page_title = "Home Page and Information";

echo"'$page_title'";

}

the GLOBALS array isn't printing out anything for [page_title] leading me to believe the program doesn't recognize it as a global variable (for some reason). it prints out the correct value at the end of the if statement, but yet thats not changed in the title. (probably because its not recognized as global). only if I added the value m00 (which I did) to page title did it print out anything, but again just in the page, and not in the title.

also, anyone know why I can't say global $page_title = value;? it won't let me assign it anything and gives me a parse error instead. I have to break it up right now into global $page title and then $page_title = value; on the next line...I'd like to avoid this.

any ideas? thanks :)

#287034

well... I do not understand the division between the "code" and the "main program"... are they in the same file, is there any include( ) ? anyway I think the first "global" in your "code" should not be there. everytime you define a variable outside a function is global. when you use the global as a keyword you want to refer to a variable outside the scope you are in (a function usually). But with no functions, there are no non-global variables afaik :)

#287052

its all in one file. there are no functions in the program. I will attach a text file of my index file so you can see what it looks like.

the framework for my page is attached. please rename it to a .php file and open with your favorite syntax-highlighting enabled text editor ;)

thank you!

I'm beginning to wonder if its because I keep opening and closing my PHP tags to maintain source-code formatting on my page :/...

index.php.txt

Attachment: index.php.txt

#287053

Um.. for one thing, in the code in the first post, "m00" doesn't have quotes around it... also, why exactly do you need a global there? A regular variable is still usable in between different <?php ?> blocks..

#287205

I thought since the blocks of code existed between the header section and body section that there would have been a problem. I guess not? I know you have to respecify even global variables (though what about session variables?) in functions, but I'm not using any right now.

I checked before I added the m00 to the code and it still didn't work. must have copied older source that I used. oops!

thank you for your help so far Mahalis

#287213