PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old June 10th, 2004, 08:27 PM
bruder bruder is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 3 bruder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 4 sec
Reputation Power: 0
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);

?>

Reply With Quote
  #2  
Old June 11th, 2004, 07:01 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
  #3  
Old June 12th, 2004, 03:27 AM
Pheifel Pheifel is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: Denmark
Posts: 174 Pheifel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 46 sec
Reputation Power: 5
Send a message via MSN to Pheifel
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()... !!

Reply With Quote
  #4  
Old June 12th, 2004, 03:09 PM
bruder bruder is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 3 bruder User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 4 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Session question -- $HTTP_SESSION_VARS scope


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway