<?php
include('../inc/conf.php');
ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(604800000, "/", SITE, false, false);
session_start();
if (!isset($_SESSION["uid"])){
echo "2";
exit;
}
if(isset($_POST['mail'])){
if(!empty($_POST['mail'])){
$mail = mysqli_real_escape_string($connect_db, trim($_POST['mail']));
function is_email($email) {
return preg_match("/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/", $email);
}
if (!is_email($mail)) { echo '0' ; exit; }
$usr = intval($_SESSION["uid"]);
$nm = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT em FROM t_users WHERE uid = '$usr'"));
$nowm = $nm['em'];
if ($nowm == $mail) { echo '5'; exit; }
mysqli_query($connect_db, "UPDATE `t_users` SET `em` = '$mail' WHERE uid = '$usr'");
echo '1';
} else { echo '4'; }
} else { echo '3'; }
?>