Session Variables problem 
Author Message
 Session Variables problem

I'm using the class from http://www.*-*-*.com/
inserted the following new function, 2nd from last within the class, in
index.php:

 function populateListLink() {
  reset ($this->oa_names);
  while (list ($key, $val) = each ($this->oa_names)) {
    if ($val == "month") {
      return;
    }
    $uri = str_replace(" ", "%20", $val);
    // now pass $uri and $val as input to JavaScript (less the 'month'
directory)
    echo " <option value=\"_top,$uri/\">&nbsp;$val</option>\n";
  }
 }

The purpose of this function is to extract the path value of subordinate
directories, and pass them to a JavaScript listbox for navigation. This all
works perfectly...from the home directory of the application. Once you use
the navigation to go down one level, there is nothing in the listbox (of
course!).

Known conditions and constraints:
* All subdirectories are one level below the application dir
* All subdirectories have their own local copy of index.php
* Have to design for pre-v4.2.0 PHP (i.e., $HTTP_SERVER_VARS)
* No assumptions can be made at to register_globals on or off
* OK to add new config vars (eg, value of /home_dir/ for comparison against
$HTTP_SERVER_VARS['PHP_SELF'])

I *believe* that the answer is to use session variables. There are a bunch of
special rules for session variables within functions, and when using
HTTP_SERVER_VARS
( http://www.*-*-*.com/ ). I tried to read
and heed, but I'm lost. If I try to sessions by  adding session_start() at
the top of the function, and attempt to register via:
    $HTTP_SESSION_VARS["uri"]  = str_replace(" ", "%20", $val);
    $HTTP_SESSION_VARS["val2"] = $val;
...it results in the generic "Cannot send session cache limiter" error. I
know that this means header info has already been sent, but I'm hard-pressed
to see what! The only thing above the class is a bunch of config vars that
get set. No print, echo, includes or white-space. If I try it this way...
    $uri  = str_replace(" ", "%20", $val);
    $val2 = $val;
    $HTTP_SESSION_VARS["uri"];
    $HTTP_SESSION_VARS["val2"];
...I get the same warning, BUT session id's are set...for everything EXCEPT
$uri and $val!

Is there a better way? If not, how can I get session variables to work?

I know JS, but I'm new to PHP. Don't think you will be insulting me by
over-explaining.  ;)

-B



Mon, 27 Jun 2005 02:20:48 GMT  
 Session Variables problem
Perhaps I went into too much detail the first time. All I need is some advice
on how to start and register a session within a function (which also happens
to be part of a class). The manual is long on warnings, but short on advice.

I need to use $HTTP_SERVER_VARS and $HTTP_SESSION_VARS, so I guess that means
they must be declared global... but where (e.g., top of script, top of class,
within function)?
======

Quote:
> I'm using the class from http://de.zend.com/codex.php?id=398&single=1. I
> inserted the following new function, 2nd from last within the class, in
> index.php:

>  function populateListLink() {
>   reset ($this->oa_names);
>   while (list ($key, $val) = each ($this->oa_names)) {
>     if ($val == "month") return;
>     $uri = str_replace(" ", "%20", $val);
>     // now pass $uri and $val as input to JavaScript (less the 'month'
> directory)
>     echo " <option value=\"_top,$uri/\">&nbsp;$val</option>\n";
>   }
>  }

> The purpose of this function is to extract the path value of subordinate
> directories, and pass them to a JavaScript listbox for navigation. This all
> works perfectly...from the home directory of the application. Once you use
> the navigation to go down one level, there is nothing in the listbox (of
> course!).

> Known conditions and constraints:
> * All subdirectories are one level below the application dir
> * All subdirectories have their own local copy of index.php
> * Have to design for pre-v4.2.0 PHP (i.e., $HTTP_SERVER_VARS)
> * No assumptions can be made at to register_globals on or off
> * OK to add new config vars (eg, value of /home_dir/ for comparison against
> $HTTP_SERVER_VARS['PHP_SELF'])

> I *believe* that the answer is to use session variables. There are a bunch
of
> special rules for session variables within functions, and when using
> HTTP_SERVER_VARS
> (http://www.php.net/manual/en/function.session-register.php). I tried to re
ad
> and heed, but I'm lost. If I try to sessions by  adding session_start() at
> the top of the function, and attempt to register via:
>     $HTTP_SESSION_VARS["uri"]  = str_replace(" ", "%20", $val);
>     $HTTP_SESSION_VARS["val2"] = $val;
> ...it results in the generic "Cannot send session cache limiter" error. I
> know that this means header info has already been sent, but I'm
hard-pressed
> to see what! The only thing above the class is a bunch of config vars that
> get set. No print, echo, includes or white-space. If I try it this way...
>     $uri  = str_replace(" ", "%20", $val);
>     $val2 = $val;
>     $HTTP_SESSION_VARS["uri"];
>     $HTTP_SESSION_VARS["val2"];
> ...I get the same warning, BUT session id's are set...for everything EXCEPT
> $uri and $val!

> Is there a better way? If not, how can I get session variables to work?

> I know JS, but I'm new to PHP. Don't think you will be insulting me by
> over-explaining.  ;)

> -B



Tue, 28 Jun 2005 14:53:18 GMT  
 Session Variables problem

Quote:

> Perhaps I went into too much detail the first time. All I need is some advice
> on how to start and register a session within a function (which also happens
> to be part of a class). The manual is long on warnings, but short on advice.

> I need to use $HTTP_SERVER_VARS and $HTTP_SESSION_VARS, so I guess that means
> they must be declared global... but where (e.g., top of script, top of class,
> within function)?

Why don't you add session_start() at the top of each page that includes
the function? You can then use session_register() in the function as the
session now exists globally.

If you use $_SERVER and $_SESSION instead of $HTTP_SERVER_VARS and
$HTTP_SESSION_VARS you don't need to declare them global in the function
as they are already declared 'superglobal'.

Alternatively you can turn output buffering on then php keeps the
headers and content until the script finishes. See
http://uk.php.net/manual/en/ref.outcontrol.php for more details.
I wouldn't recommend this in most circumstances though as holding the
output requires memory on the server.

Kevin Thorpe



Tue, 28 Jun 2005 17:36:54 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Session Variable Problem

2. Problem with Netscape and session variables?

3. Global Variable / Sessions / ASP Application type Variable

4. session var and variable variable

5. Tornado6 OCX and session variables

6. how to access Session variables?

7. php session variables on multiple pages

8. BRL 2.1.25: better debugging; session variables

9. Nested arrays with classes in session variables

10. help with session variable

11. How long does PHP store variables and sessions?

12. register_session when session variable already registered

 

 
Powered by phpBB® Forum Software