Session variable reading doesn't work

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

    Session variable reading doesn't work

    L.S.

    I am developing a PHP-login script (on Lycos Tripod) that uses Session to
    pass on variables. Below is the entire (stripped) structure that I use. It
    opens a page where you can Set and Read the session variable BUT ... It
    doesn't work!!! It seems that both set- and readlink open their own private
    session.

    How can I get the read-link to access the proper session variable?

    Below is a full testing environment. It uses frames and should work fine ...
    but it doesn't. I use this directory-structure:
    testindex.php
    testmenu.php
    testhome.php
    login001 [dir]
    -----testsetvar.php
    -----testreadvar.php
    fb001 [dir]
    -----testfb.php
    -----testframe1.php
    -----testframe2.php

    The content of the files is:
    *************** *************** *********
    testindex.php
    *************** *************** *********
    <HTML>
    <HEAD>
    <title>page</title>
    </HEAD>
    <FRAMESET BORDER="on" cols="200,*">
    <FRAME SRC="testmenu.p hp" NAME=menu>
    <FRAME SRC="testhome.p hp" NAME=main>
    </FRAMESET>
    </HTML>

    *************** *************** *********
    testmenu.php
    *************** *************** *********
    <HTML>
    <HEAD>
    <title>Menu</title>
    </HEAD>
    <BODY>
    <A href='login001/testsetvar.php' target='main'>S et</A> the session
    variable<BR><BR >
    <A href='fb001/testfb.php' target='main'>R ead</A> the session variable
    </BODY>
    </HTML>

    *************** *************** *********
    testhome.php
    *************** *************** *********
    <HTML>
    <HEAD>
    <title>Home</title>
    </HEAD>
    <BODY>
    This is the Homepage
    </BODY>
    </HTML>

    *************** *************** *********
    testsetvar.php
    *************** *************** *********
    <?php
    session_start() ;
    session_registe r('testvar');

    $testvar="this is the testvariable";
    if(session_is_r egistered('test var')):
    $reg="the testvariable IS registered";
    else:
    $reg="the testvariable is NOT registered";
    endif;

    print("var = ".$testvar."<BR >reg = ".$reg."<BR>ses sion ID =
    ".session_id(). "<BR>");
    ?>

    *************** *************** *********
    testreadvar.php
    *************** *************** *********
    <?
    session_start() ;

    if(session_is_r egistered('test var')):
    $reg="the testvariable IS registered";
    else:
    $reg="the testvariable is NOT registered";
    endif;
    print("var = ".$testvar."<BR >reg = ".$reg."<BR>ses sion ID =
    ".session_id(). "<BR>");
    ?>

    *************** *************** *********
    testfb.php
    *************** *************** *********
    <HTML>
    <HEAD>
    <title>page</title>
    </HEAD>
    <FRAMESET BORDER="on" cols="*,150">
    <FRAME SRC="testframe1 .php" NAME=frame1>
    <FRAME SRC="testframe2 .php" NAME=frame2>
    </FRAMESET>
    </HTML>

    *************** *************** *********
    testframe1.php
    *************** *************** *********
    <?
    include("../login001/testreadvar.php ");
    ?>
    <HTML>
    <HEAD>
    <title>Home</title>
    </HEAD>
    <BODY>
    <BR>This is frame1<BR>
    </BODY>
    </HTML>

    *************** *************** *********
    testframe2.php
    *************** *************** *********
    <HTML>
    <HEAD>
    <title>Home</title>
    </HEAD>
    <BODY>
    <BR>This is frame2
    </BODY>
    </HTML>

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



  • Nathan

    #2
    Re: Session variable reading doesn't work

    Peter say...
    [color=blue]
    > session_registe r('testvar');
    >
    > $testvar="this is the testvariable";[/color]

    I might be wrong, but first off is it that you have to register testvar
    after you've actually declared it? As I say I may be way off there.

    The other thing is to check if you've got register_global s on in your
    php.ini file.

    If it's off (which is the default IIRC) then the above won't work.
    Alternatively, just use $_SESSION["testvar"] = "this is the testvariable";

    With the $_SESSION[] array, you do not need to use session_registe r.

    If I used session_registe r with register_global s off, I got error messages
    and things didn't work as planned.

    using $_SESSION is quicker anyway, because you can just treat it like you
    might $testvar but without having to bother with another function
    (session_regist er) everytime.

    --
    Nathan.
    XBL Gamertag: Cowfield

    Bow to the Cow!

    Comment

    • Robert Jirik

      #3
      Re: Session variable reading doesn't work

      Monday 28 of July 2003 14:01, Nathan wrote in alt.php:
      [color=blue]
      >
      > I might be wrong, but first off is it that you have to register testvar
      > after you've actually declared it? As I say I may be way off there.[/color]

      that's the point ... but as you said, it's better to use $_SESSION['var']
      anyway ...

      --
      Robert Jirik
      [mailto:robert(a t)aristoteles(d ot)xhaven(dot)n et]
      public PGP key: http://xhaven.net/robert/pgp_key.asc
      -
      "Real programmers don't work from 9 to 5. If any real programmers
      are around at 9am it's because they were up all night"

      Comment

      • Peter

        #4
        Re: Session variable reading doesn't work

        I removed the references to session_start() and session_is_regi stered() and
        replaced them with the $_SESSION way of setting and reading the variable but
        .... ALAS it still doesn't work. Any other ideas?

        Thanks for your replies anyway, Peter.



        Comment

        • Peter

          #5
          Re: Jippie .. Session variable reading does work

          I finally got it working. I went back to the original code, using
          session_start() etc. Nathan was right!! Apparantly, you must first declare
          the variable and then make a call to session_registe r().

          Thank you all for your replies.

          Peter.


          Comment

          • Nathan

            #6
            Re: Jippie .. Session variable reading does work

            Peter say...
            [color=blue]
            > Nathan was right!![/color]

            Yay!

            --
            Nathan.
            XBL Gamertag: Cowfield

            Bow to the Cow!

            Comment

            Working...