Solved

Session variables problem in functions

Posted on 2003-12-05
4
419 Views
Last Modified: 2008-03-06
I am having problems with initializing session variables inside functions
While writing PHP scripts I need to set some session variables inside some functions
Example:
             function some_function()
             {
                    ...........
                    session_register("message");
                    $message="You are NOT authorized to view this page";
                   ........
             }

The same code for setting session variables in working fine when I use in the main part of the PHP i.e. not inside any function.

Can anyone figure out my mistake in setting session variables??

Suggestions and solutions are welcome

-Aayush
0
Comment
Question by:aayushpuri
  • 2
4 Comments
 
LVL 6

Expert Comment

by:rjdown
Comment Utility
Use the super global variable $_SESSION["message"] instead
0
 
LVL 6

Expert Comment

by:aolXFT
Comment Utility


$message =& $_SESSION['message'];
0
 
LVL 24

Expert Comment

by:shivsa
Comment Utility
$message = $_SESSION['message'];
0
 
LVL 6

Accepted Solution

by:
aolXFT earned 100 total points
Comment Utility
No Shivsa, put the & back in.

Otherwise the value will be lost, after he exits the function.
Alternatively

$message = &$_SESSION['message'];

could be used, the difference is that with my first one, you are using the copy by reference operator, where as in my second example you are copying a reference.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now