Global Variable / Sessions / ASP Application type Variable 
Author Message
 Global Variable / Sessions / ASP Application type Variable

I'm having 2 problems:
1. Why is the MyGlobalValue variable showing up as part of the User's
   Session?
2. Is there a way that would allow users to be part of a global
   session temporarily to get the value from a global variable
   (like in ASP)?

Note: a. You have to hit refresh once to see the full results of the
         code listed below.
      b. I haven't got a clue how to pass a value from 1 session to
         another session within 1 php script
      c. Databases and files can't be used. The value must stay in
         the server's memory and can never be passed to the client
         machine.

<?PHP
  session_start();                      //Start a session if one
                                        //hasn't already been started

  $PreviousSession=session_id("MyApp"); //Set the ID for the session
                                        //that gets used by every user

  //-------------- Supposedly different session (start) --------------

  session_start();                      //Start the "MyApp" session

  session_register("MyGlobalValue");    //Register this variable
                                        //within this session (this
                                        //session only - I thought)

  if ($MyGlobalValue == "")             //If it hasn't been assigned
                                        //yet
    {
    $MyGlobalValue=$PreviousSession;    //Assign a value that shows
                                        //the original connection is
                                        //the only one that set it
    }

  session_id($PreviousSession);         //Got back to the original
                                        //user specific connection

  //-------------- Supposedly different session (end) --------------

  session_start();                      //Restart the "User Specific"
                                        //session

  session_register("Name");             //Register a couple of
  session_register("Count");            //variables specifc to
                                        //this user

  $Name = "Johnny Smith";

  $Count++;                             //Increment counter with each
                                        //page load
?>

<HTML>
<HEAD>
<TITLE>Testing of a Global Variable</TITLE>
</HEAD>
<BODY>

<?PHP print "Total Count for $Name: $Count" ?>

<hr>

<?PHP
  echo '<pre>';

  print "SESSION: " . session_id() . "<BR>";
  print_r ($_SESSION);
  print "<hr>";
  print "REQUEST:<BR>";
  print_r ($_REQUEST);

  echo '</pre>';
?>

<hr>
</BODY>
</HTML>



Wed, 26 Oct 2005 23:26:26 GMT  
 Global Variable / Sessions / ASP Application type Variable
If you have register_globals turned off then you cannot use
session_register.

Tony Marston


Quote:
> I'm having 2 problems:
> 1. Why is the MyGlobalValue variable showing up as part of the User's
>    Session?
> 2. Is there a way that would allow users to be part of a global
>    session temporarily to get the value from a global variable
>    (like in ASP)?

> Note: a. You have to hit refresh once to see the full results of the
>          code listed below.
>       b. I haven't got a clue how to pass a value from 1 session to
>          another session within 1 php script
>       c. Databases and files can't be used. The value must stay in
>          the server's memory and can never be passed to the client
>          machine.

> <?PHP
>   session_start();                      //Start a session if one
>                                         //hasn't already been started

>   $PreviousSession=session_id("MyApp"); //Set the ID for the session
>                                         //that gets used by every user

>   //-------------- Supposedly different session (start) --------------

>   session_start();                      //Start the "MyApp" session

>   session_register("MyGlobalValue");    //Register this variable
>                                         //within this session (this
>                                         //session only - I thought)

>   if ($MyGlobalValue == "")             //If it hasn't been assigned
>                                         //yet
>     {
>     $MyGlobalValue=$PreviousSession;    //Assign a value that shows
>                                         //the original connection is
>                                         //the only one that set it
>     }

>   session_id($PreviousSession);         //Got back to the original
>                                         //user specific connection

>   //-------------- Supposedly different session (end) --------------

>   session_start();                      //Restart the "User Specific"
>                                         //session

>   session_register("Name");             //Register a couple of
>   session_register("Count");            //variables specifc to
>                                         //this user

>   $Name = "Johnny Smith";

>   $Count++;                             //Increment counter with each
>                                         //page load
> ?>

> <HTML>
> <HEAD>
> <TITLE>Testing of a Global Variable</TITLE>
> </HEAD>
> <BODY>

> <?PHP print "Total Count for $Name: $Count" ?>

> <hr>

> <?PHP
>   echo '<pre>';

>   print "SESSION: " . session_id() . "<BR>";
>   print_r ($_SESSION);
>   print "<hr>";
>   print "REQUEST:<BR>";
>   print_r ($_REQUEST);

>   echo '</pre>';
> ?>

> <hr>
> </BODY>
> </HTML>



Thu, 27 Oct 2005 19:00:23 GMT  
 Global Variable / Sessions / ASP Application type Variable

Quote:
> Note: a. You have to hit refresh once to see the full results of the
>          code listed below.
>       b. I haven't got a clue how to pass a value from 1 session to
>          another session within 1 php script
>       c. Databases and files can't be used. The value must stay in
>          the server's memory and can never be passed to the client
>          machine.

One can use shared memory (shm) on UNIX an alike systems. There is
nothing that can be done on microsoft systems.

                                                     DG



Thu, 27 Oct 2005 20:46:50 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Class variables / global variables / Init variables

2. asp, php and global variables

3. session var and variable variable

4. More details about Surprising LV global variable of type 2

5. Surprising LV global variable of type 2

6. creating "global type variables"

7. Life cycle of a mod_python application and scope of global variables

8. Global object in ASP (calling other scripting languages in ASP pages)

9. Get data into my variables from ASP

10. Tornado6 OCX and session variables

11. how to access Session variables?

12. php session variables on multiple pages

 

 
Powered by phpBB® Forum Software