\n"; } else { /* On recupere le domaine, c'est a dire les caracteres APRES le @ */ $domain = substr($email, $atIndex+1); /* On recupere le nom, c'est a dire les caracteres AVANT le @ */ $local = substr($email, 0, $atIndex); /* Longueur du nom */ $localLen = strlen($local); /* Longueur du domaine */ $domainLen = strlen($domain); /* Si le nom fait plus de 64 caracteres ou moins d'un caractere l'adresse n'est pas valide */ if ($localLen < 1 || $localLen > 64) { $isValid = false; if ($verbose) echo "bad local length :".$localLen."
\n"; } /* Si le domaine fait plus de 255 caracteres ou moins d'un caractere l'adresse n'est pas valide */ else if ($domainLen < 1 || $domainLen > 255) { $isValid = false; if ($verbose) echo "bad domain length :".$domainLen."
\n"; } /* Si la longueur totale de l'adresse est inférieure a 6 caracteres, l'adresse est invalide */ else if(strlen($email) < 6) { $isValid = false; if ($verbose) echo "bad email length :".strlen($email)."
\n"; } /* test si le nom commence ou termine par un . */ else if ($local[0] == '.' || $local[$localLen-1] == '.') { $isValid = false; if ($verbose) echo "dot found in local in bad position :
\n"; } /* deux point consecutifs */ else if (preg_match('/\\.\\./', $local)) { $isValid = false; if ($verbose) echo " 2 dots found in local :
\n"; } /* presence de caracteres non valides dans le domaine*/ else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { $isValid = false; if ($verbose) echo " bad char in domain : ".$domain."
\n"; } /* points consecutifs dans le domaine */ else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; if ($verbose) echo " 2 consecutive dots in domain : ".$domain."
\n"; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; if ($verbose) echo " bad chars in local : ".$local."
\n"; } } if((bool)$checkdns) { /* Verification de l'existence du domaine et de son champs MX */ getmxrr($domain, $test); if ($isValid && count($test) == 0) { // domain not found in DNS $isValid = false; if ($verbose) echo " domain not found in DNS : ".$domain."
\n"; } } // Test sur les mots interdits if (ereg("spam", $email)) $isValid = false; if (ereg("spamming", $email)) $isValid = false; if (ereg("root", $email)) $isValid = false; if (ereg("rooting", $email)) $isValid = false; if (ereg("administrateur", $email)) $isValid = false; if (ereg("admin", $email)) $isValid = false; if (ereg("administrator", $email)) $isValid = false; if (ereg("report", $email)) $isValid = false; if (ereg("reporting", $email)) $isValid = false; if (ereg("abuse", $email)) $isValid = false; } return $isValid; } /** * Suppression des accents * a teste avec d'autres encodages * */ function removeaccents($string) { $string= strtr(utf8_decode($string), utf8_decode("ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ"), "aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn"); return $string; } /* function removeaccents($string) { $string= strtr(($string), utf8_decode("ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ"), "aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn"); return $string; } */ /** * Fonction de suppression des caracteres invalides pour les urls * */ /** * Fonction de suppression des caracteres invalides pour les urls * */ function make_url_compatible_iso($string) { $string= strtr($string,utf8_decode("€’ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ,;:!§/.?*_@)}+({'#~ []`<>"), "e-aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn-------------------------"); return $string; } function make_url_compatible($string) { $string= strtr(utf8_decode($string),utf8_decode("€’ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ,;:!§/.?*_@)}+({'#~ []`<>"), "e-aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn-------------------------"); return $string; } function make_filename_compatible($string, $iso = false) { if (preg_match("/(.+)\.([a-zA-Z]+)+$/", $string, $matches)) { $extension = $matches[2]; $basename = $matches[1]; if ($iso) $basename = make_url_compatible_iso($basename); else $basename = make_url_compatible($basename); return $basename.".".$extension; } else return false; } function _createCropedImage ($src_filename, $path, $width = 100, $height = 100, $top = 0, $left = 0, $dst_w = 100, $dst_h = 100, $prefix = "small_") { if (exif_imagetype($path.'/'.$src_filename) == IMAGETYPE_GIF) { $create_func = "imagecreatefromgif"; $output_func = "imageGIF"; } elseif(exif_imagetype($path.'/'.$src_filename) == IMAGETYPE_JPEG) { $create_func = "imagecreatefromjpeg"; $output_func = "imageJPEG"; } elseif(exif_imagetype($path.'/'.$src_filename) == IMAGETYPE_PNG) { $create_func = "imagecreatefrompng"; $output_func = "imagePNG"; } else return false; $dst_filename = $path.'/'.$prefix.$src_filename; $src = $create_func($path.'/'.$src_filename); $new = imagecreatetruecolor($dst_w, $dst_h); imagecopyresampled($new, $src, 0, 0, $top, $left, $dst_w, $dst_h, $width, $height); if ($output_func == "imageJPEG") $output_func($new, $dst_filename, 100); elseif ($output_func == "imagePNG") $output_func($new, $dst_filename, 7); else $output_func($new, $dst_filename); //imageJPEG($new, $dst_filename, 90); if (is_file($dst_filename)) chmod($dst_filename, 0644); imagedestroy($new); } /** * Creation d'un url a partir d'un texte * */ function create_url_friendly($texte) { setlocale(LC_ALL, 'fr_FR.UTF8'); // $texte = utf8_encode($texte); $texte = iconv('UTF-8', 'ASCII//TRANSLIT', $texte); $texte = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $texte); $texte = strtolower(trim($texte, '-')); $texte = preg_replace("/[\/_|+ -]+/", "-", $texte); /* $texte = strtolower(make_url_compatible($texte)); $texte = str_replace("-de-","-",$texte); $texte = str_replace("-du-","-",$texte); $texte = str_replace("-le-","-",$texte); $texte = str_replace("-la-","-",$texte); $texte = str_replace("-les-","-",$texte); $texte = str_replace("-un-","-",$texte); $texte = str_replace("-une-","-",$texte); $texte = str_replace("-des-","-",$texte); $texte = str_replace("-a-","-",$texte); $texte = str_replace("-au-","-",$texte); $texte = str_replace("-ou-","-",$texte); $texte = str_replace(chr(128),"euros",$texte); $texte = str_replace(chr(38),"-",$texte); $texte = str_replace(chr(34),"",$texte); for($t=129;$t<=255;$t++) { $texte = str_replace(chr($t),"-",$texte); } while(strstr($texte,"--")) { $texte = str_replace("--","-",$texte); } $texte = trim($texte,"-"); */ return $texte; } /** * Verifcation des noms (ville, nom de famille, etc) * */ function checkName($name) { if (preg_match("/[^a-zA-Z\-\s']/", removeaccents(stripslashes($name)))) return false; return true; } function checkPostalCode($cp) { if (strlen($cp) != 5) return false; if (preg_match("/[^0-9]/", $cp)) return false; if ($cp < 01000) return false; if ($cp >= 99000) return false; return true; } function checkDepNb($nb) { if ($nb == "2A" || $nb == "2B") return true; if (strlen($nb) < 2 || strlen($nb) > 3) return false; if (preg_match("/[^0-9]/", $nb)) return false; if (intval($nb) > 95 && (intval($nb) < 971 || intval($nb) > 974)) return false; return true; } function checkList($value, $valid_values) { if (in_array($value, $valid_values)) return true; return false; } function checkPassword($password) { // Test sur les caracteres non elligibles for($i = 0; $i < strlen($password); $i++) { $value = ord($password[$i]); if($value > 127) { return false; } } if (strlen($password) > 30 || strlen($password) < 7) return false; return true; } function split_us_date($us_date) { $date = array(); if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $us_date, $regs)) { $date['day'] = $regs[3]; $date['month'] = $regs[2]; $date['year'] = $regs[1]; } return $date; } function to_us_date($date) { $new_date = array(); if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) return $date; elseif (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $date, $regs)) { $new_date['day'] = $regs[1]; $new_date['month'] = $regs[2]; $new_date['year'] = $regs[3]; return $new_date['year']."-".$new_date['month']."-".$new_date['day']; } } function to_us_datetime($date) { $new_date = array(); if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $date, $regs)) return $date; elseif (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $date, $regs)) { $new_date['day'] = $regs[1]; $new_date['month'] = $regs[2]; $new_date['year'] = $regs[3]; $new_date['hour'] = $regs[4]; $new_date['minute'] = $regs[5]; $new_date['sec'] = $regs[6]; return $new_date['year']."-".$new_date['month']."-".$new_date['day']." ". $date['hour'].":".$date['minute'].":".$date['sec']; } } function us2fr_date($us_date) { $date = array(); if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $us_date, $regs)) { $date['day'] = $regs[3]; $date['month'] = $regs[2]; $date['year'] = $regs[1]; return $date['day']."/".$date['month']."/".$date['year']; } else return $us_date; } function us2fr_datetime($us_date) { $date = array(); if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $us_date, $regs)) { $date['day'] = $regs[3]; $date['month'] = $regs[2]; $date['year'] = $regs[1]; $date['hour'] = $regs[4]; $date['minute'] = $regs[5]; $date['sec'] = $regs[6]; return $date['day']."/".$date['month']."/".$date['year']." ". $date['hour'].":".$date['minute'].":".$date['sec']; } } function fr2us_date($fr_date) { $date = array(); if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4})", $fr_date, $regs)) { $date['day'] = $regs[1]; $date['month'] = $regs[2]; $date['year'] = $regs[3]; return $date['year']."-".$date['month']."-".$date['day']; } else return ($fr_date); } function fr2us_datetime($fr_date) { $date = array(); if (ereg ("([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $fr_date, $regs)) { $date['day'] = $regs[1]; $date['month'] = $regs[2]; $date['year'] = $regs[3]; $date['hour'] = $regs[4]; $date['minute'] = $regs[5]; $date['sec'] = $regs[6]; return $date['year']."-".$date['month']."-".$date['day']." ". $date['hour'].":".$date['minute'].":".$date['sec']; } } /** * Renvoie la date au format US du timestamp passé en parametre. * Si aucun parametre est passé, renvoie date du jour */ function date_us($ts = 0) { if ($ts == 0) { $ts = time(); } $jour = date("d",$ts); $mois = date("m",$ts); $annee = date("Y",$ts); return $annee."-".$mois."-".$jour; } /** * Teste la validite d'une date au format US * Peut tester egalement si une date se trouve * dans une intervalle, si $agemax et $agemin sont * specifies * @date date au format us * @agemax int age maximun * @agemin int age minimun */ function checkUsDate($date, $agemax = false, $agemin = false) { $isValid = false; if(ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) { if (checkdate($regs[2], $regs[3], $regs[1])) return true; } return false; } function checkTelNumber($number) { if (preg_match("/[^0-9']/", $number) || strlen($number) != 10 ) return false; return true; } function checkTelephoneNumber($number) { if (preg_match("/^0[1234589]{1}[0-9]{8}$/", $number)) return true; return false; } function checkMobileNumber($number) { if (preg_match("/^0[67]{1}[0-9]{8}$/", $number)) return true; return false; } function checkInteger($intger) { if(is_numeric($intger) && is_int(intval($intger))) return true; return false; } // Simplifie les requetes SQL function myQuery($bdd, $sql, $mode = MDB2_FETCHMODE_ASSOC) { $ret = $bdd->query($sql); if (PEAR::isError($ret)) die(__FILE__." ".__LINE__." ".$ret->getMessage().'
'.$sql); $ret = $ret->fetchAll($mode); return ($ret); } // Simplifie les requetes SQL function myExec($bdd, $sql, $mode = MDB2_FETCHMODE_ASSOC) { $ret = $bdd->exec($sql); if (PEAR::isError($ret)) die(__FILE__." ".__LINE__." ".$ret->getMessage()); return ($ret); } #Fonction dlookup, permet de récupérer une seule valeur (ou calcul) d'une requete function dlookup($mdb2,$champ,$table,$criteres, $debug = false) { // echo $champ." ".$table." ".$criteres."
"; $requete = "SELECT ".$champ." FROM ".$table; if (strlen($criteres) > 0) { $requete .= " WHERE ".$criteres; } if ($debug) echo $requete."
"; $res = $mdb2->query($requete); if (PEAR::isError($res)) { die($res->getMessage()); } if ($res !== false) { $row_dlookup = $res->fetchOne(); return $row_dlookup; } else { return ""; } } /* Permet de verifier sur le parametre est un entier */ function isInteger($input){ return preg_match('@^[-]?[0-9]+$@',$input) === 1; } function isPositive($input){ if (preg_match('@^[-]?[0-9]+$@',$input) === 1 && (int)$input > 0) return true; return false; } function testCheckFunction($function, $values) { foreach ($values as $val) { if ($function($val)) echo $val." valide
"; else echo $val." NON VALIDE
"; } } /* Renvoie les infos sur l'url en cours */ function infos_url($mdb2,$url) { if(dlookup($mdb2,"count(*)","url","url_simple='".$url."'") > 0) { $sql = "SELECT url_titre,url_desc,url_tags,url_fichier,url_id FROM url WHERE url_simple='".$url."'"; $res =& $mdb2->query($sql); // Gestion erreur if (PEAR::isError($res)) { die($res->getMessage()); } // Lecture resultat if ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { $infos = array('titre' => $row['url_titre'], 'description' => $row['url_desc'], 'tags' => $row['url_tags'], 'fichier' => $row['url_fichier'], 'url_id' => $row['url_id'], 'erreur' => false); } else { $infos = array('erreur' => true); } } else { $infos = array('erreur' => true); } return $infos; } function debug_array($array) { echo "
";
		print_r($array);
		echo "
"; } function get_param($mdb2,$lib) { return dlookup($mdb2,"param_val","concours.param","param_lib = '".$lib."'"); } function _createResizedImage ($src_filename, $path, $littleWidth = 100, $littleHeight = 100, $prefix = "small_") { if (exif_imagetype($path.'/'.$src_filename) == IMAGETYPE_GIF) { $create_func = "imagecreatefromgif"; $output_func = "imageGIF"; } elseif(exif_imagetype($path.'/'.$src_filename) == IMAGETYPE_JPEG) { $create_func = "imagecreatefromjpeg"; $output_func = "imageJPEG"; } elseif(exif_imagetype($path.'/'.$src_filename) == IMAGETYPE_PNG) { $create_func = "imagecreatefrompng"; $output_func = "imagePNG"; } else return false; $dst_filename = $path.'/'.$prefix.$src_filename; $src =& $create_func($path.'/'.$src_filename); $width = imageSX($src); $height = imageSY($src); $w_ratio = $littleWidth / $width; $h_ratio = $littleHeight / $height; if ($h_ratio < 1 || $w_ratio < 1) { if ($w_ratio <= $h_ratio) { $dst_width = $littleWidth; $dst_height = ($dst_width / $width) * $height; } else if ($h_ratio < $w_ratio) { $dst_height = $littleHeight; $dst_width = ($dst_height / $height) * $width; } $dst =& imagecreatetruecolor($dst_width, $dst_height); imagealphablending($dst, false); imagesavealpha($dst ,true); imagecopyresized($dst, $src, 0, 0, 0, 0, $dst_width, $dst_height, imageSX($src), imageSY($src)); if ($output_func == "imageJPEG") $output_func($dst, $dst_filename, 100); else $output_func($dst, $dst_filename); imagedestroy($dst); } else { imagealphablending($src, false); imagesavealpha($src ,true); if ($output_func == "imageJPEG") $output_func($src, $dst_filename, 100); elseif ($output_func == "imagePNG") { $output_func($src, $dst_filename, 7); } else $output_func($src, $dst_filename); } if (is_file($dst_filename)) chmod($dst_filename, 0644); imagedestroy($src); } function formatBytes($bytes, $precision = 2) { $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= pow(1024, $pow); return round($bytes, $precision) . ' ' . $units[$pow]; } /* $tests = array(12, 123, 33, "15A", "20A", "je suis le chiffre 4", "4456", "12", "A23", "2A", "900", "971"); testCheckFunction("checkDepNb", $tests); */ function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } function htmlentities_deep($value, $charset = "ISO-8859-15") { $value = is_array($value) ? array_map('htmlentities_deep', $value) : htmlentities($value, ENT_COMPAT, $charset); return $value; } function us2fr_date_deep($value) { $value = is_array($value) ? array_map('us2fr_date_deep', $value) : us2fr_date($value); return $value; } function fr2us_date_deep($value) { $value = is_array($value) ? array_map('fr2us_date_deep', $value) : fr2us_date($value); return $value; } function fr2us_datetime_deep($value) { $value = is_array($value) ? array_map('fr2us_date_deep', $value) : fr2us_datetime($value); return $value; } function utf8encode_deep($value) { $value = is_array($value) ? array_map('utf8_encode', $value) : utf8_encode($value); return $value; } function list_dir($dir, $filetype = "") { if ($handle = opendir($dir)) { $files = array(); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (empty($filetype)) $files[] = $file; elseif (ereg("\.".$filetype."$", $file)) $files[] = $file; } } closedir($handle); return $files; } else echo "Impossible de lire le dossier ".$dir; } function del_array_key($array, $key) { for ($i = $key; $i < (count($array) - 1); $i++) { $array[$i] = $array[$i + 1]; } array_pop($array); return $array; } function test_url($url) { $url_chunks = parse_url($url); if (empty($url_chunks['scheme']) || empty($url_chunks['host'])) return false; $data = get_headers($url); if ($data === false) return false; if (preg_match("/200/", $data[0])) return true; return false; } function extractInfos($from, $search) { $str = ''; if (strstr($from, $search)) { $pos = strpos($from, $search); $i = $pos + strlen($search); while (isset($from[$i]) && $from[$i] != ']') $str .= $from[$i++]; } return ($str); } function sendToBDD($str) { return addslashes(utf8_decode($str)); } function readFromBDD($str) { return utf8_encode(stripslashes($str)); } function formatTel($number) { return preg_replace("/([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/", "\\1 \\2 \\3 \\4 \\5", $number); } /var/www/ch-pau.fr/index.php 31 MDB2 Error: connect failed