Last active
January 10, 2024 10:41
-
-
Save bohwaz/e14df1e88e9e06aa3857e8b6f1181bf9 to your computer and use it in GitHub Desktop.
Vérification de validité de numéro INE d'étudiant (BEA/Scolarix/APOGEE)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Licence : domaine public ou WTFPL | |
// 2018 BohwaZ <http://bohwaz.net/> | |
function check_ine($ine) | |
{ | |
if (!function_exists('bcmod')) | |
{ | |
throw new \LogicException('bcmath is required'); | |
} | |
$ine = strtoupper(trim($ine)); | |
if (strlen($ine) != 11) | |
{ | |
return false; | |
} | |
// Numéro INE/BEA | |
// format AABBNNNNNNM | |
// AA = Académie, BB = Année, NNNNNN = Numéro (préfixé par D si provisoire), M = modulo 23 | |
if (preg_match('!^(\d\d)(\d\d)([A-Z\d]{6})([A-Z])$!', $ine, $match)) | |
{ | |
list(, $academie, $annee, $numero, $modulo) = $match; | |
// Numéro INE provisoire | |
$provisoire = substr($numero, 0, 1) == 'D'; | |
// Académie 00 (international) n'accepte pas de numéro provisoire | |
if ($academie == '00' && $provisoire) | |
{ | |
return false; | |
} | |
// Liste des académies | |
// 00 International | |
// 01-28 Paris-Réunion | |
// 31-33, 41-44 DOM-TOM | |
// 80 INAA | |
static $liste_academies = ['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', | |
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, | |
31, 32, 33, 40, 41, 42, 43, 44, 50, 51, 59, 80, 99]; | |
if (!in_array($academie, $liste_academies)) | |
{ | |
return false; | |
} | |
// Année >= 90 OU Année <= (Année courante sur 2 chiffres) | |
if ($annee < 90 && $annee > date('y')) | |
{ | |
return false; | |
} | |
// Lettres I, O et Q ne sont pas utilisées | |
$lettres = array_flip(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', /*'I', */ | |
'J', 'K', 'L', 'M', 'N', /*'O'*/ 'P', /*'Q'*/ 'R', 'S', 'T', 'U', | |
'V', 'W', 'X', 'Y', 'Z']); | |
// Remplacement | |
$numero = strtr($numero, $lettres); | |
$modulo = $lettres[$modulo]; | |
$check = bcmod($academie . $annee . $numero, 23); | |
if ($check == $modulo) | |
{ | |
return true; | |
} | |
} | |
// Numéro INE établissement enseignement supérieur | |
// (Cocktail/Scolarix/APOGEE) | |
// AAAAABCCCCM | |
// AAAAA = code établissement base 36 (code UAI) | |
// B = numéro année base 36 | |
// CCCC = numéro d'ordre étudiant base 36 | |
// M = modulo 10 base 10 | |
if (preg_match('!^[A-Z\d]{10}\d$!', $ine, $match)) | |
{ | |
//$etablissement = base_convert(substr($ine, 0, 5), 36, 10); | |
//$annee = 1990 + base_convert(substr($ine, 5, 1), 36, 10); | |
//$numero = base_convert(substr($ine, 6, 4), 36, 10); | |
$modulo = substr($ine, -1); | |
$ine = base_convert(substr($ine, 0, 10), 36, 10); | |
$check = bcmod($ine, 10); | |
if ($modulo == $check) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bonjour, désolé de vous déranger !
Je souhaite savoir si ils existent des documents qui expliquent le formatage des nouveaux INE ?
Après avoir recherché scrupuleusement dans de dizaines de pages de recherche sur Google, je ne trouve malheusement rien.
J'espère que l'un d'entre nous pourra nous éclaircir sur les INE..