Web Analytics Made Easy -
StatCounter Sessions not being set? - CodingForum

Announcement

Collapse
No announcement yet.

Sessions not being set?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sessions not being set?

    I'm using MySQL and Sessions for my login system. The MySQL part of the login is fine, but for some reason my sessions wont set.

    Here is my code
    PHP Code:
        function login($username,$password){
            
    $this->username $username;
            
    $this->password $password;
            
    $this->connect();
            
    $query "SELECT id,user,pass FROM blogusers WHERE user='{$this->username}' AND pass='{$this->password}'";
            
    $result mysql_query($query) or die(mysql_error());
            if(
    mysql_num_rows($result) == "0"){
                echo 
    "Wrong username and/or password";
            }
            else{
                
    session_start();
                
    $_SESSION['username'] = $this->username;
                
    $_SESSION['password'] = $this->password;
                
    Header("Location: base.php?mode=cp");
            }
        } 
    So, when I check to see if the session is established by
    PHP Code:
    if(isset($_SESSION['username']) && isset($_SESSION['password'])) 
    It returns false, because it does not redirect to the control panel and prompts to login.

    Any ideas?

    Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Try renaming the sessionvariables. Like

    $_SESSION['xxxuser'] = $username;
    $_SESSION['xxxpass'] = $password;

    i've noticed on some machines (probably due to register_globals=on ) that if you use the same name for a sessionvar then for a regular var in your script, that the value isn't set, so i now always use unique varnames (even across collections)
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment


    • #3
      Hmm. That doesn't seem to work either.
      Stevie Peele
      Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
      #dev - any programming,etc. question
      #design - design discussion and critque
      #central - general chat
      Come join us!

      Comment


      • #4
        do you have a session_start() before the if(isset($_SESSION['username']) && isset($_SESSION['password']))
        Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

        Comment


        • #5
          I think that was it. My server is acting screwy right now. I'll confirm it later.

          Thanks
          Stevie Peele
          Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
          #dev - any programming,etc. question
          #design - design discussion and critque
          #central - general chat
          Come join us!

          Comment

          Working...
          X