Aqua-Soft Forums: [help] php global variables question - Aqua-Soft Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[help] php global variables question Rate Topic: -----

#1 User is offline   MDZ61384 Icon

  • Group: Member
  • Posts: 793
  • Joined: 08-November 02

Posted 27 May 2005 - 05:22 PM

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 :)
0

#2 User is offline   dreadnaut Icon

  • Group: Member
  • Posts: 614
  • Joined: 28-September 04

Posted 27 May 2005 - 06:54 PM

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 :)
0

#3 User is offline   MDZ61384 Icon

  • Group: Member
  • Posts: 793
  • Joined: 08-November 02

Posted 27 May 2005 - 07:00 PM

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 :/...

Attached File(s)


0

#4 User is offline   Mahalis Icon

  • Group: Member
  • Posts: 298
  • Joined: 15-May 04

Posted 28 May 2005 - 05:26 AM

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 blocks..
0

#5 User is offline   MDZ61384 Icon

  • Group: Member
  • Posts: 793
  • Joined: 08-November 02

Posted 28 May 2005 - 06:42 AM

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
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users