1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| <?php
include"db.php" ;
include"form.php";
include"auth.php";
include"session.php" ;
function Speciauxcarct($chaine) {
$utf8 = array(
'/[áàâãªä]/u' => 'a',
'/[ÁÀÂÃÄ]/u' => 'A',
'/[ÍÌÎÏ]/u' => 'I',
'/[íìîï]/u' => 'i',
'/[éèêë]/u' => 'e',
'/[ÉÈÊË]/u' => 'E',
'/[óòôõºö]/u' => 'o',
'/[ÓÒÔÕÖ]/u' => 'O',
'/[úùûü]/u' => 'u',
'/[ÚÙÛÜ]/u' => 'U',
'/ç/' => 'c',
'/Ç/' => 'C',
'/ñ/' => 'n',
'/Ñ/' => 'N',
'//' => '-', // conversion d'un tiret UTF-8 en un tiret simple
'/[]/u' => ' ', // guillemet simple
'/[«»]/u' => ' ', // guillemet double
'/ /' => ' ', // espace insécable (équiv. à 0x160)
);
return preg_replace(array_keys($utf8), array_values($utf8), $chaine);
}
function dequote($chaine) {
$utf8 = array(
'/[]/u' => ' ', // guillemet simple
'/[«»]/u' => ' ', // guillemet double
);
return preg_replace(array_keys($utf8), array_values($utf8), $chaine);
}
function nettoyerChaine($chaine) {
$chaine = strtolower($chaine); // on passe la chaine de caractère en minuscule
return $chaine = str_replace(' ', '-', $chaine); // on remplace les espaces par des tirets
}
function slugify($text){
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
if (function_exists('iconv'))
{
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
}
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text))
{
return 'n-a';
}
return $text;
}
function str_random($length){
$aphabet = "0123456789azertyuiopqsdfghjklmwxcvbnAZERTYUIOPQSDFGHJKLMWXCVBN";
return substr(str_shuffle(str_repeat($aphabet, $length)),0,$length);
}
function reconnect_from_coockie(){
include"db.php" ;
if(isset($_COOKIE['remember']) && !isset($_SESSION['Auth'])){
$remember_token = $_COOKIE['remember'];
//var_dump($remember_token); die();
$parts = explode('==', $remember_token);
$user_id = $parts[0];
$req = $db->prepare("SELECT * from users WHERE id = ? ");
$req->execute([$user_id]);
$user = $req->fetch();
if($user){
$expected = $user_id . '==' . $user[$remember_token] . sha1($user_id .'ratonlaveurs');
if($expected = $remember_token){
$_SESSION['Auth']= $user;
setcookie('remember', $remember_token, time() + 60 + 60 + 24 + 7);
if( $_SESSION['Auth']['role'] == 'mnjim'){
$_SESSION['flash']['success']="Vous etes bien connecté";
}
else if( $_SESSION['Auth']['role'] == 'user'){
$_SESSION['flash']['success']="Vous etes bien connecté";
}
}
else{
setcookie('remember', NULL, -1);
}
}
else{
setcookie('remember', NULL, -1);
}
}
}
?> |
Partager