Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- David Heller
March 18, 2013, 11:05 pm
rate this thread
I have the following code snippet:
public function register($name, $rule, $dat_file, $server =
DEFAULT_SERVER, $port = DEFAULT_PORT)
$this->m_rules[$name] = $rule;
// $cmd = "$$name = new GTCM_GNP($dat_file, $server, \
$$name = new GTCM_GNP($dat_file, $server, $port);
$this->m_names = $name;
$this->m_rules[$name] = array($rule);
What exactly does "return $_SESSION[$name]" do? it looks like it just
returns the $name argument in the function list. Or does it save it as
a session variable also? Why not just do: "return $name;" ?? Is there
a better way to do this without using session variables or super
globals? $_SESSION was originally $GLOBALS changing it to $_SESSION
did not break it and it seemed like a better alternative but probably
not the best way. By the way this code was originally written for php
4.0.6 if that makes any difference.
Re: How to avoid the use of session variables in this script
The _SESSION super global refers to a standardized PHP cookie.
Somewhere in the init code there should be a call to session_start().
What is going on 'under the hood' is that a cookie named PHPSESSID (or
something like that) is created and initialized. Setting
$_SESSION[<mumble>] to some value (where <mumble> is some arbitary key)
is a way of saving values across pages. The contents of the _SESSION
array is used to initialize the cookie when the headers are sent. When
some future page is accessed by the web browser that received this
cookie, it passes the cookie in the headers and session_start()
retrieves the cookie and re-initializes the _SESSION array from the
contents of the cookie.
2009, published by O'Reilly Media, Inc. ISBN 978-0-596-15713-5 covers
the use of _SESSION on pages 289-296.
Robert Heller -- 978-544-6933 / email@example.com
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments