Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

session varaible within function.... 1

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I have a function which draws a header on each exported page of a pdf document created in fpdf; however, a session variable passed to the page is not available within the function.

How do I make the session variable global to be accessed within the function?

TIA,

-Allen M.
 
The $_SESSION variable is a super-global which means its available everywhere.


Perhaps if you show s what you are doing we can point out the error?

Note, that session_start() must always be called prior to using the $_SESSION var.






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
I fixed it..

I had to add the GLOBAL command to the variable within the function to make it visible outside...

Tnx.
 
Again, that should not be necessary, and could lead to trouble down the line.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi

Then better pay attention to Phil's words :
Phil said:
Again, that should not be necessary, and could lead to trouble down the line
The superglobal behavior works as is :
Code:
[teal]<?php[/teal]

[navy]$_SESSION[/navy][teal][[/teal][green][i]'foo'[/i][/green][teal]]=[/teal][green][i]'bar'[/i][/green][teal];[/teal]

[COLOR=darkgoldenrod]fun[/color][teal]();[/teal]

[b]function[/b] [COLOR=darkgoldenrod]fun[/color][teal]()[/teal]
[teal]{[/teal]
  [b]echo[/b] [navy]$_SESSION[/navy][teal][[/teal][green][i]'foo'[/i][/green][teal]];[/teal]
[teal]}[/teal]
Note that I not started the session in the sample code only to show that the superglobal behavior not depends on it.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top