Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Session variables problem in functions

Posted on 2003-12-05
4
Medium Priority
?
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

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

Expert Comment

by:aolXFT
ID: 9884510


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

Expert Comment

by:shivsa
ID: 9885050
$message = $_SESSION['message'];
0
 
LVL 6

Accepted Solution

by:
aolXFT earned 400 total points
ID: 9885170
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

671 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