Session

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathanwb
    New Member
    • Mar 2008
    • 39

    Session

    I dont think I am doing this correctly. Sorry I am a newby..

    I can get it to login and display the username, but if you leave the page and come back to it.. it wont show the username again of the person who just loged in. I dont think the cookie is being set correctly.


    Here is the code that I am using...

    [php]

    if ($mode == 'login')
    {
    post('un,up');
    $unn = mysql_escape_st ring($un);
    $upp = mysql_escape_st ring($up);
    $qc = mysql_query("SE LECT * FROM `instructors` WHERE `username` = '$unn' AND `password` = '$upp' AND `isadmin`='1'") ; if (mysql_num_rows ($qc) > 0)

    {

    $rc = mysql_fetch_ass oc($qc);
    extract($rc);
    $logged = 1;
    session_registe r('logged');
    $_SESSION['logged'] = $id;
    session_registe r('MyID');
    $_SESSION['MyID'] = $id;
    $mode = '';
    }

    else $error = "<span class='text'><f ont color=red>Incor rect login information</font></span>";
    }



    if (!isset($_SESSI ON['logged']))
    {
    include ("navtop.php ");
    include ("nav.php");


    echo "
    [/php]

    Thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Your code does not contain any echo of the username, so?

    Ronald

    Comment

    • realin
      Contributor
      • Feb 2007
      • 254

      #3
      and do we really need to use session_registe r() ??

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by realin
        and do we really need to use session_registe r() ??
        No you do not. Don't use it, use $_SESSION and do not forget to start every script using $_SESSION with session_start() .

        Let me show some thoughts from the php documentation on this.
        Originally posted by php docs
        If your script uses session_registe r(), it will not work in environments where the PHP directive register_global s is disabled.

        If you are using $_SESSION (or $HTTP_SESSION_V ARS), do not use session_registe r.
        Ronald

        Comment

        • realin
          Contributor
          • Feb 2007
          • 254

          #5
          Originally posted by ronverdonk
          No you do not. Don't use it, use $_SESSION and do not forget to start every script using $_SESSION with session_start() .

          Let me show some thoughts from the php documentation on this.Ronald
          yup, this is what i have been thinkin, cause session_registe r() was a way old thing, but i din know the above mentioned fact about registering globals, thanks Ronald, you always add up my knowledge base :)

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            So what has the OP, nathanwb, to say about this? Any solution in sight?

            Ronald

            Comment

            • nathanwb
              New Member
              • Mar 2008
              • 39

              #7
              Sorry for the delay in responding.. I went to books a million and got a book :)

              I have solved the issue, thanks for the imput though.

              Comment

              • TheServant
                Recognized Expert Top Contributor
                • Feb 2008
                • 1168

                #8
                Originally posted by nathanwb
                Sorry for the delay in responding.. I went to books a million and got a book :)

                I have solved the issue, thanks for the imput though.
                Was it including session_start() ?

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  Originally posted by nathanwb
                  Sorry for the delay in responding.. I went to books a million and got a book :)

                  I have solved the issue, thanks for the imput though.
                  Please share ýour solution with us, so we can learn from it.

                  Ronald

                  Comment

                  Working...