WHERE 子句中是否有空格?
我正在为我的新项目编写帐户验证系统。目前注册/连接页面没问题!只有帐户验证页面不起作用。确认邮件通过注册页面中的电子邮件发送。
您可以在这里注册:http://protect.you-test.ch/inscription.php
您可以在此处连接:http://protect.you-test.ch/connexion.php
问题是当用户名有空间时,该请求没有空间'工作:
$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";
但是当没有空间时,它可以工作!
编辑:问题是随机发生的。有时它有时起作用有时不起作用(带有空格)。
这个问题只出现在这个页面上,不会出现在连接页面上!
当前代码:
<?php
include("mysql_connect.php");
$login = base64url_decode($_GET['login']);
$login = trim($login);
$login = mysql_real_escape_string($login);
echo '</br>'.$login.'</br>';
echo '</br>'.$user_key.'</br>';
$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);
if ($data['0'] == 0) {
$clebdd = $data['user_key'];
$actif = $data['verified_user'];
if($actif == '1') {
echo "Votre compte est déjà actif !";
} else {
if($user_key == $clebdd) {
$sql = 'UPDATE users SET verified_user = 1 WHERE login="'.$login.'"';
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
echo "Votre compte a bien été activé !";
} else {
echo "Erreur ! Votre compte ne peut être activé ...1";
}
}
} else {
echo "Erreur ! Votre compte ne peut être activé ...2";
}
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
I'm coding an account validation system for my new project. Currently register/connexion pages are okay ! Only hte account verification page doesn't work. The confirmation mail is send via email in the register page.
you can register here : http://protect.you-test.ch/inscription.php
you can connect here : http://protect.you-test.ch/connexion.php
The problem is when the username has space this requests doesnt' work :
$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";
but when there is no space, it works !
EDIT : The problem occurs randomly. SOmetimes it works sometime not (with spaces).
This problem only occurs on this page and not on the connexion page !
Current code :
<?php
include("mysql_connect.php");
$login = base64url_decode($_GET['login']);
$login = trim($login);
$login = mysql_real_escape_string($login);
echo '</br>'.$login.'</br>';
echo '</br>'.$user_key.'</br>';
$sql = "SELECT user_key,verified_user FROM users WHERE login='".$login."'";
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
$data = mysql_fetch_array($req);
if ($data['0'] == 0) {
$clebdd = $data['user_key'];
$actif = $data['verified_user'];
if($actif == '1') {
echo "Votre compte est déjà actif !";
} else {
if($user_key == $clebdd) {
$sql = 'UPDATE users SET verified_user = 1 WHERE login="'.$login.'"';
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
echo "Votre compte a bien été activé !";
} else {
echo "Erreur ! Votre compte ne peut être activé ...1";
}
}
} else {
echo "Erreur ! Votre compte ne peut être activé ...2";
}
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,空格会导致字符串比较失败:
当通过常规相等测试时,这是三个完全不同的字符串,即使人类会将它们解释为相同。
您可以尝试
在将字符串填充到查询中之前去除字符串两侧的空格。
Yes, spaces will throw off a string comparison:
are three completely different strings when put through a regular equality test, even though a human would intepret them as the same.
You could try
to strip whitespace from both sides of the string before stuffing it into your query.
在 PHP 脚本中的
$login
变量上添加TRIM
。例如:修剪($login)
add
TRIM
on$login
variable in your php script. ex:trim($login)