title: PHP: User Login System / Check if User has acess to a page
body: <p>This is a bit noob question but.. Its happens sometimes to everybody.</p>
  
  <p>I never worked with $_SESSION so once i need a login system i've used Dreamweaver to do one for me.</p>
  
  <p>I have a page where he asks for user name and password.
  And if loggin successful its goes to other page. Else it says in the login page.</p>
  
  <p>The problem its that the Login, system that once worked, now isn't working.
  Because the he stays in the login page. And i've done a "echo $_SESSION['MM_Username'];"</p>
  
  <p>And nothing returned. So i think it means that i isn't creating the cookie for access??</p>
  
  <p>Right? I think that a echo on the session displays something.</p>
  
  <p>Well can i have some help guys? Maybe a simple login system. Not a Dreamweaver loggin.</p>
  
  <p>I will post the user login code in the login page.</p>
  
  <pre><code>// *** Validate request to login to this site.
  if (!isset($_SESSION)) {
    session_start();
  }
  
  $loginFormAction = $_SERVER['PHP_SELF'];
  if (isset($_GET['accesscheck'])) {
    $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  }
  
  if (isset($_POST['username'])) {
    $loginUsername=$_POST['username'];
    $password=$_POST['passe'];
    $MM_fldUserAuthorization = "power";
    $MM_redirectLoginSuccess = WWW."/administrador";
    $MM_redirectLoginFailed = WWW."/login";
    $MM_redirecttoReferrer = false;
    mysql_select_db($database_dbconnect, $dbconnect);
  
    $LoginRS__query=sprintf("SELECT username, passwd, power FROM `user` WHERE username=%s AND passwd=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
  
    $LoginRS = mysql_query($LoginRS__query, $dbconnect) or die(mysql_error());
    $loginFoundUser = mysql_num_rows($LoginRS);
    if ($loginFoundUser) {
  
      $loginStrGroup  = mysql_result($LoginRS,0,'power');
  
      //declare two session variables and assign them
      $_SESSION['MM_Username'] = $loginUsername;
      $_SESSION['MM_UserGroup'] = $loginStrGroup;       
  
      if (isset($_SESSION['PrevUrl']) &amp;&amp; false) {
        $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];  
      }
      header("Location: " . $MM_redirectLoginSuccess );
    }
    else {
      header("Location: ". $MM_redirectLoginFailed );
    }
  }
  </code></pre>
  
  <p>I worked. it the changes you see there that are in the $MM_redirectLoginSuccess and $MM_redirectLoginFailed and nothing changed in the database.</p>
  
  <p>If its tired some. Just post a simple login user code, i've found some but, not good ones. That i do the rest.</p>
  
  <p>Do you know whats its wierd? It worked. I saved, then turn off computer, then when i came back didn't worked.</p>
  
  <p>Thanks again.</p>