我正在为我的移动应用程序在 API 中使用 PHP 和 JSON。我试图编写一个注册模块,但我的部分条件语句没有按预期工作。
如果语句 1:
if(!isset($_GET['username']) || !isset($_GET['password']) || !isset($_GET['imei']) || !isset($_GET['imie']) || !isset($_GET['nazwisko']) || !isset($_GET['email']) || !isset($_GET['zgoda']) || !isset($_GET['telefon']) || !isset($_GET['zgoda2']) || !isset($_GET['kraj']));
{
$returning = array('error' => 'Invalid query');
echo json_encode($returning);
break;
}
当缺少参数时,它应该给出一个错误,但它总是给出一个错误。
我的查询:
username=konrad12&password=xxx&imei=000000000000000&nazwisko=Potter&imie=Ronald&email=xxx@xxx.pl&zgoda=1&telefon=000&zgoda2=1&kraj=Poland
如果语句 2:
if(strlen($c) != 15 || !validEmail($f) || strlen($g) != 1 || strlen($i) != 1 || wez_id_kraju($j) == 0)
{
$returning = array('error' => 'Invalid query');
echo json_encode($returning);
break;
}
当 var 值不正确时,它应该给出一个错误,但它总是给出一个错误。
我的变量:
$z = mysql_real_escape_string($_GET['username']);
$b = mysql_real_escape_string($_GET['password']);
$c = mysql_real_escape_string($_GET['imei']);
$d = mysql_real_escape_string($_GET['nazwisko']);
$e = mysql_real_escape_string($_GET['imie']);
$f = mysql_real_escape_string($_GET['email']);
$g = mysql_real_escape_string($_GET['zgoda']);
$h = mysql_real_escape_string($_GET['telefon']);
$i = mysql_real_escape_string($_GET['zgoda2']);
$j = mysql_real_escape_string($_GET['kraj']);
如果语句 3:
if($g != 0 or 1 || $i != 0 or 1)
{
$returning = array('error' => 'Invalid query');
echo json_encode($returning);
break;
}
当 $g 或 $i 的值不是 1 或 0 时,它应该报错,但它总是报错。
请帮助我,我尝试了很多东西,但我找不到解决方案
@编辑 :
我的有效电子邮件功能:
function validEmail($email)
{
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex)
{
$isValid = false;
}
else
{
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
$domainLen = strlen($domain);
if ($localLen < 1 || $localLen > 64)
{
// local part length exceeded
$isValid = false;
}
else if ($domainLen < 1 || $domainLen > 255)
{
// domain part length exceeded
$isValid = false;
}
else if ($local[0] == '.' || $local[$localLen-1] == '.')
{
// local part starts or ends with '.'
$isValid = false;
}
else if (preg_match('/\\.\\./', $local))
{
// local part has two consecutive dots
$isValid = false;
}
else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
{
// character not valid in domain part
$isValid = false;
}
else if (preg_match('/\\.\\./', $domain))
{
// domain part has two consecutive dots
$isValid = false;
}
else if
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
str_replace("\\\\","",$local)))
{
// character not valid in local part unless
// local part is quoted
if (!preg_match('/^"(\\\\"|[^"])+"$/',
str_replace("\\\\","",$local)))
{
$isValid = false;
}
}
if ($isValid && !(checkdnsrr($domain,"MX") ||
↪checkdnsrr($domain,"A")))
{
// domain not found in DNS
$isValid = false;
}
// I add that text ...
mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD);
mysql_select_db(DB_BASE);
$q = "SELECT * FROM `system_domeny`";
$a = mysql_query($q);
while($wynik = mysql_fetch_array($a))
{
if($domena == $wynik[1]) $isValid = false;
}
// ...
}
return $isValid;
}