Sharing variables (beginner's question)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mladen Gogala

    Sharing variables (beginner's question)

    How can I share variables between two processes?
    Here is my problem?

    File test1.php:
    -------------------------------------------------------------------
    <?php
    session_start() ;
    $var1="This should";
    $var2="be displayed";
    $_SESSION[ 'var1' ]=$var1;
    $_SESSION[ 'var2' ]=$var2;
    if (session_is_reg istered('var1') ) {
    print "Var1 is registered<br>" ;
    }
    if (session_is_reg istered('var2') ) {
    print "Var2 is registered<br>" ;
    }
    print "<A HREF=/work/test2.php>Secon d File</A>";
    ?>

    File test2.php
    -------------------------------------------------------------------
    <?php
    if (session_is_reg istered('var1') ) {
    print "test2:Var1 is registered<br>" ;
    }
    if (session_is_reg istered('var2') ) {
    print "test2:Var2 is registered<br>" ;
    }

    $var1=$_SESSION[ 'var1' ];
    $var2=$_SESSION[ 'var2' ];
    print "$var1 $var2 <br>";
    ?>


    Nothing gets displayed. I think that the problem lies in the fact that
    these two files are handled by two processes, but I also think that
    httpd process should be able to get the cookie from the browser and
    read the sess* file containing the variables:
    var1|s:11:"This should";var2|s: 12:"be displayed";

    How can I achieve proper sharing of the information, short of developing
    a complex scheme with shmop, which would mean complete relink and,
    basically, reinstallation of PHP? I apologize in advance if the question
    is elementary, but I was absolutely unable to find the answer in either
    PHP online pages or O'Reilly book.

    --
    Trust me, I know what I'm doing. (Sledge Hammer)

  • Pedro Graca

    #2
    Re: Sharing variables (beginner's question)

    Mladen Gogala wrote:[color=blue]
    > How can I share variables between two processes?[/color]

    You *must* start the session in *every* script that uses session
    variables.


    *************** *************** *************** *************** ********

    <quote src="http://www.php.net/session_is_regi stered" edited="true">

    *CAUTION*

    DO NOT use session_is_regi stered() and $_SESSION in the same script!

    </quote>

    *************** *************** *************** *************** ********

    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    Working...