<?php
class Logininicio extends Conectar 
{
	public function __construct(){
		parent::__construct();
	}
	
	
	
	
	
public function login(){

 

  $usuario=$_POST['usuario'];
  $cv=$_POST['clave'];
  $clave_encriptada=password_hash($cv, PASSWORD_DEFAULT);
  try{
  $stmt = $this->datab->prepare("SELECT * FROM admin WHERE usuario=?"); 
  $stmt->bindValue(1, htmlentities($usuario),PDO::PARAM_STR);
  $stmt->execute();
  $data=$stmt->fetch();

  if (password_verify($cv, $data['clave'])){
  //////////////////////////////////////////////////////////
  $_SESSION['id_cp']=$data['id'];
  setcookie('id_cp',$data['id'],time() + (200 * 24 * 60 * 60),'/');
 
 
 
  
  header('Location:'.ruta.'');
  exit;
 
  //////////////////////////////////////////////////////////
  }else{
  header('Location:'.ruta.'?pagina=login&error=1');
  exit;
  } 
  }
  catch(PDOException $e) {
  echo '{"error":{"text":'. $e->getMessage() .'}}';
  }
  }
    
	
	
	
	
	
	
	
}