|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Session question -- $HTTP_SESSION_VARS scope
I'm writing a progam that uploads a file using post. The script that processes the upload sets a session var. $HTTP_SESSION_VARS['message'].
At the end of the script that process the post I do this: header('Location:'.'index.php'; The session variable is in scope in index.php. However, if I call a function from index, the session variable is notset? I thought it was global? See the example script below. message is displayed, message2 is empty. Thanks. <?php function display_message ($message) { $message2 = $HTTP_SESSION_VARS['message']; echo $message; echo $message2; } session_start(); //PROCESS A FORM HERE, AND USE ANOTHER FILE //TO PROCESS THE UPLOAD. and sets the session variable //$HTTP_SESSION_VARS['message'] = 'processed in form' $message = $HTTP_SESSION_VARS['message']; display_message ($message); ?> |
|
#2
|
||||
|
||||
|
Maybe registering the variable would help. In any case, it's probably better practice to pass the variable to your function than to rely on the global.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
and using the session_start() at the very beggining of the script. BEFORE the $_SESSION is set would properly help. Because the $_SESSION cant be used outside the session_start()... !!
|
|
#4
|
|||
|
|||
|
I figured out what I was doing wrong. Turns out that the psuedocode above does isn't exactly how my script worked.
My problem was that I was using: $HTTP_SEESSION_VARS['message'], and another variable called $message. Since I have 'register globals' enabled, these two globals are referencing the same variable. From now on I'll prefix all references to global arrays with a prefix: $HTTP_SEESSION_VARS['session_message'] Thanks. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Session question -- $HTTP_SESSION_VARS scope |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|