php - Cookies and variables -


i've created login class web app , work, i've created infamous "keep me logged in" - checkbox , don't work. here's class login:

<?php      error_reporting(e_all ^ e_notice);  class login {      private $error;     private $connect;     private $email;     private $password;     public $row;  public function __construct(pdo $connect) {      $this->connect  = $connect;     $this->error    = array();     $this->row      = $row;   }  public function dologin() {      $this->email = htmlspecialchars($_post['email']);     $this->password = htmlspecialchars($_post['password']);     $this->rememberme = $_post['rememberme'];      if($this->validatedata()) {          $this->fetchinfo();      }      return count($this->error) ? 0 : 1;  }  public function validatedata() {      if(empty($this->email) || empty($this->password)) {          $this->error[] = "täyttämättömiä kenttiä";      } else {      return count($this->error) ? 0 : 1;  }  }  public function fetchinfo() {      $query = "select * users email = :email ,  activation_token null";     $stmt = $this->connect->prepare($query);     $stmt->execute(array(                  ':email' => $this->email,          ));         if($stmt->rowcount() == 0) {         $this->error[] = "väärä käyttäjätunnus tai salasana";         return 0;      } else {              $row = $stmt->fetch(pdo::fetch_assoc);                  $_session['user_id'] = $row['user_id'];                 $_session['email'] = $row['email'];                 $_session['name'] = $row['name'];                 $_session['profilepic'] = $row['profilepic'];               if(isset($this->rememberme)) {                 setcookie("loggedin", "yes", time() + 25200);              }      }      if (register::cryptpass($this->password) != $row['password']) {     $this->error[] = "virheelliset kirjautumistiedot";      } else {          return true;      }         return count($this->error) ? 0 : 1;      }    public function displayerrors() {      if(!count($this->error)) return;         echo "<div class='login_error'>";         foreach($this->error $key=>$value) {         echo "<p>".$value."</p>";      }  echo "</div>";  }   public function dologout() {      session_destroy();  }  } ?> 

and here's small part of code file i'm checking if session or cookie set:

<?php if (isset($_session['email']) || isset($_cookie['loggedin'])) { ?>               <div id="header_container_isloggedin">      <div class="container_12">     <header id="header">     <div class="grid-12">      <ul id="menu">      <li class="profile-name">          <a href="profile.php?id=<?php echo $_session['user_id']; ?>">         <span class="header_username">      <img src="images/thumbnails/<?php echo $_session['profilepic']; ?>"          class="profile_evensmaller"/>      <span class="header_name"><?php echo $_session['name']; ?></span></span></a>      </li>  </ul> <?php } ?> 

the problem everytime cookie set, doesn't display profile picture or name since they've saved inside of $_session variable. how should approach , work. know right it's not safest method, since i'm not generating hashes cookie, right thing i'm interested in, 1 work.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -