- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
几个月前我为我的项目构建了一个注册功能,直到昨天它一直运行良好,我不太确定发生了什么,因为我好几个星期没有对它进行任何更改,上次我检查时它正在工作。我已经尝试自己调试它,但我找不到任何问题,而且我不确定还能做什么!
代码分布在多个页面上,但本质上,这是发生了什么:
HTML 构造
<?php require_once("clean.php"); ?>
<ul class="nav pull-right"><?php
if (isset($_SESSION['logged'])) {?>
<li><a href="profile.php">Profile</a></li>
<li><a href="logout.php">Logout</a></li><?php
} else {?>
<li><a href="#register" class="account-register" data-toggle="modal" title="Register a new Screening account">Register</a></li>
<li><a href="#login" class="account-login" data-toggle="modal" title="Login to your Screening profile">Login</a></li><?php
}?>
</ul>
<div id="register" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="registerLabel" aria-hidden="true">
<?php require_once("register-controller.php"); ?>
<!-- reCAPTCHA jQuery -->
<script type="text/javascript">
var RecaptchaOptions = {
theme : 'white'
};
</script>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="registerLabel" class="modal-title">Register a new Screening account</h3>
</div>
<form name="register" action="" method='POST' enctype="multipart/form-data">
<div class="modal-body">
<?php echo $register_bad_message; ?>
<?php echo $register_good_message; ?>
<input class="input-block-level" type="text" name="firstname" placeholder="First Name">
<input class="input-block-level" type="text" name="lastname" placeholder="Last Name">
<input class="input-block-level" type="email" name="email" placeholder="Email">
<input type="file" class="profile-picture-upload" name="profile-image" alt="profile-image">
<input class="input-block-level" type="password" name="password" placeholder="Password">
<input class="input-block-level" type="password" name="confirm-password" class="span3" placeholder="Confirm Password">
<?php include ("recaptcha_form.php") ?>
</div>
<div class="modal-footer">
<button type="button" class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button type="submit" class="btn btn-success" name="submit" value="Sign up!">Sign up!</button>
</div>
</form>
</div>
Clean.php
<?php
/*
ini_set('display_errors', 1);
error_reporting(E_ALL);
*/
function clean_string($string) {
$string = trim($string);
$string = utf8_decode($string);
$string = str_replace("#", "#", $string); $string = str_replace("%", "%", $string);
if (mysql_real_escape_string($string)) {
$string = mysql_real_escape_string($string);
}
if (get_magic_quotes_gpc()) {
$string = stripslashes($string);
}
return htmlentities($string);
}
?>
register-controller.php
<?php
/*
ini_set('display_errors', 1);
error_reporting(E_ALL);
*/
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
if( $this->image_type == IMAGETYPE_GIF || $this->image_type == IMAGETYPE_PNG ) {
$current_transparent = imagecolortransparent($this->image);
if($current_transparent != -1) {
$transparent_color = imagecolorsforindex($this->image, $current_transparent);
$current_transparent = imagecolorallocate($new_image, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
imagefill($new_image, 0, 0, $current_transparent);
imagecolortransparent($new_image, $current_transparent);
} elseif( $this->image_type == IMAGETYPE_PNG) {
imagealphablending($new_image, false);
$color = imagecolorallocatealpha($new_image, 0, 0, 0, 127);
imagefill($new_image, 0, 0, $color);
imagesavealpha($new_image, true);
}
}
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}
//Clean
echo "before clean";
$submit = clean_string($_POST['submit']);
echo "after clean";
if ($submit == 'Sign up!') {
$first_name = clean_string($_POST['first-name']);
$last_name = clean_string($_POST['last-name']);
$email = clean_string($_POST['email']);
$password = clean_string($_POST['password']);
$confirm_password = clean_string($_POST['confirm-password']);
//Output variables
$register_bad_message = '';
$register_good_message = '';
require_once($_SERVER['DOCUMENT_ROOT'] . '/recaptcha/recaptchalib.php');
$privatekey = "6Ldbd8ASAAAAAFz8VT29H5w4WLNjsbI-mFY2QkaC";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
$errMessage = $resp->error;
$register_bad_message = '<div class="alert alert-error">The reCAPTCHA you entered wasn\'t correct. Please try again.</div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
} else {
if ($first_name&&$last_name&&$email&&$password&&$confirm_password) {
if ($password == $confirm_password) {
if (strlen($password) > 25 || strlen($password) < 6) {
$register_bad_message = '<div class="alert alert-error">Please enter a password between 6 and 25 characters.</div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
} else {
require_once("db_connect.php");
if($db_server) {
$first_name = clean_string($first_name);
$last_name = clean_string($last_name);
$email = clean_string($email);
$password = clean_string($password);
echo "1";
mysql_select_db($db_database);
$taken = mysql_query("SELECT email FROM users WHERE email='$email'");
$count = mysql_num_rows($taken);
if ($count > 0) {
$register_bad_message = '<div class="alert alert-error">The email you have entered is already associated with a Screening account. Please choose another.</div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
} else {
if ($_FILES) {
//Put file properties into variables
$file_name = $_FILES['profile-image']['name'];
$file_size = $_FILES['profile-image']['size'];
$file_tmp_name = $_FILES['profile-image']['tmp_name'];
//Determine filetype
switch ($_FILES['profile-image']['type']) {
case 'image/jpeg': $ext = "jpg"; break;
case 'image/png': $ext = "png"; break;
default: $ext = ''; break;
}
if ($ext) {
//Check filesize
if ($file_size < 5242880) {
//Process file - resize, clean up filename and move to safe location
$image = new SimpleImage();
$image->load($file_tmp_name);
$image->resizeToWidth(250);
$image->save($file_tmp_name);
$n = "$file_name";
$n = ereg_replace("[^A-Za-z0-9.]", "", $n);
$n = strtolower($n);
$n = "avatars/$n";
move_uploaded_file($file_tmp_name, $n);
} else {
$register_bad_message = '<div class="alert alert-error">Please ensure your chosen file is less than 5MB.</div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
}
} else {
$register_bad_message = '<div class="alert alert-error">Please ensure your image is of filetype .jpg or.png.</div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
}
}
$password = md5($password);
$query = "INSERT INTO users (first_name, last_name, email, password, image) VALUES ('$first_name', '$last_name', '$email', '$password', '$n')";
mysql_query($query) or die("Insert failed. " . mysql_error() . "<br />" . $query);
$register_good_message = '<div class="alert alert-success">Registration successful!
<br />
<a href='#login' data-toggle='modal' title='Login to your Screening profile'>Login now</a></div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
}
} else {
$register_bad_message = '<div class="alert alert-error">Error: could not connect to the database.</div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
}
require_once("db_close.php");
}
} else {
$register_bad_message = '<div class="alert alert-error">Passwords failed to match. Please try again.</div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
}
} else {
$register_bad_message = '<div class="alert alert-error">Please fill in all fields before continuing.</div>';?>
<script>
$('a.account-register').trigger('click');
</script><?php
}
}
}
?>
如果我打开错误报告,我收到的消息是:
清理前警告:mysql_real_escape_string():\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean 中的用户 ''@'localhost'(使用密码:NO)拒绝访问.php on line 11 Warning: mysql_real_escape_string(): A link to the server could not be established in\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 after clean注意:未定义索引:第 100 行\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\register-controller.php 中的名字 警告:mysql_real_escape_string():用户 '' 的访问被拒绝@'localhost'(使用密码:NO)在\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php 第 11 行警告:mysql_real_escape_string(): 指向服务器的链接可能\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 注意:Undefined index: last-name in\ICS-FILESHARE\WWW\newmedia.leeds .ac.uk\ug10\cs10aer\screening_new\reg ister-controller.php on line 101 Warning: mysql_real_escape_string(): Access denied for user ''@'localhost' (using password: NO) in\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 警告:mysql_real_escape_string(): A link to the server could not be established in\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 警告:mysql_real_escape_string():拒绝访问\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php 中的用户 ''@'localhost'(使用密码:NO) 11 警告:mysql_real_escape_string():无法在第 11 行的\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php 中建立到服务器的链接警告:mysql_real_escape_string():\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php 第 11 行警告中的用户 ''@'localhost'(使用密码:NO)被拒绝访问:mysql_real_escape_string():到服务器的链接无法在第 11 行的\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php 中建立警告:mysql_real_escape_string():用户 ''@'localhost' 的访问被拒绝(使用密码:NO) in\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php on line 11 Warning: mysql_real_escape_string(): A link to the server could not be established in\ICS -FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening_new\clean.php 第 11 行
但我已经检查了我的数据库连接,一切似乎都正常 - 网站上的其他功能,例如登录和添加、删除和修改数据库详细信息都运行良好,并且它们使用相同的数据库连接脚本,所以它是只是这个注册功能突然坏了,原因我不明白。
最佳答案
在调用mysql_real_escape_string
之前,您必须连接到数据库。当代码到达这一点时,连接尚未建立:
//Clean
echo "before clean";
$submit = clean_string($_POST['submit']);
echo "after clean";
或者,您可以使用不太安全的 mysql_escape_string
函数。 mysql_real_escape_string
需要数据库连接,因为它需要了解连接的字符编码。
关于php - 注册功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15598123/
我正在构建一个 RCP 应用程序,其中每个季度都会更新功能/插件。因此,如果用户选择自动更新功能/插件,则会下载更新插件的新 jar,但旧插件仍在使用我不再使用的磁盘空间。 我厌倦了删除包含旧 jar
我如何从外部 Controller 功能中调用 Controller 内部的功能,例如电话间隙回调功能 这是 Controller 外部定义的功能 function onDeviceReady()
如果某个功能(例如 MediaSource)可用,我如何使用 Google Dart 检查。 new MediaSource() 抛出一个错误。如何以编程方式检查此类或功能是否存在?有任何想法吗?是否
我正在尝试运行 Azure Orchestrations,突然我开始从 statusQueryGetUri 收到错误: 协调器函数“UploadDocumentOrchestrator”失败:函数“U
我见过 iPhone 上的应用程序,如果在 3.0 上运行,将使用 3.0 功能/API,例如应用内电子邮件编辑器,如果在 2.x 上运行,则不使用这些功能,并退出应用程序以启动邮件相反。 这是怎么做
这是 DB 规范化理论中的一个概念: Third normal form is violated when a non-key field is a fact about another non-ke
如果我定义 #if SOMETHING #endif 而且我还没有在任何地方定义 SOMETHING。 #if 中的代码会编译吗? 最佳答案 当#if的参数表达式中使用的名称未定义为宏时(在所有其他宏
我刚刚澄清了 A* 路径查找应该如何在两条路径具有相等值的 [情况] 下运行,无论是在计算期间还是在结束时,如果有两条相等的短路径。 例如,我在我的起始节点,我可以扩展到两个可能的节点,但它们都具有相
Java有没有类似下面的东西 宏 一种遍历所有私有(private)字段的方法 类似于 smalltalk symbols 的东西——即用于快速比较静态字符串的东西? 请注意,我正在尝试为 black
这个程序应该将华氏度转换为摄氏度: #include int main() { float fahrenheit, celsius; int max, min, step;
当打开PC缓存功能后, 软件将采用先进先出的原则排队对示波器采集的每一帧数据, 进行帧缓存。 当发现屏幕中有感兴趣的波形掠过时, 鼠标点击软件的(暂停)按钮, 可以选择回看某一帧的波形
我有一个特殊的(虚拟)函数,我想在沙盒环境中使用它: disable.system.call eval(parse(text = 'model.frame("1 ~ 1")'), envir = e
使用新的 Service 实现,我是否必须为我的所有服务提供一个 Options 方法? 使用我的所有服务当前使用的旧 ServiceBase 方法,OPTIONS 返回 OK,但没有 Access-
我正在阅读 Fogus 的关于 Clojure 的喜悦的书,在并行编程章节中,我看到了一个函数定义,它肯定想说明一些重要的事情,但我不知道是什么。此外,我看不到这个函数有什么用 - 当我执行时,它什么
我有大量的 C 代码,大部分代码被注释掉和/或 #if 0。当我使用 % 键匹配 if-else 的左括号和右括号时,它也匹配注释掉的代码。 有没有办法或vim插件在匹配括号时不考虑注释掉或#if 0
我有这个功能: map(map(fn x =>[x])) [[],[1],[2,3,4]]; 产生: val it = [[],[[1]],[[2],[3],[4]]] 我不明白这个功能是如何工作的。
我使用 Visual Studio 代码创建了一个函数应用程序,然后发布了它。功能应用程序运行良好。我现在在功能门户中使用代码部署功能(KUDU)并跳过构建。下面是日志 9:55:46 AM
我有一个数据框df: userID Score Task_Alpha Task_Beta Task_Charlie Task_Delta 3108 -8.00 Easy Easy
我真的无法解决这个问题: 我有一个返回数据框的函数。但是,数据框仅打印在我的控制台中,尽管我希望将其存储在工作空间中。我怎样才能做到这一点? 样本数据: n <- 32640 t <- seq(3*p
有没有办法找出所有可能的激活器命令行选项? activator -help仅提供最低限度的可用选项/功能列表,但所有好的东西都隐藏起来,即使在 typesafe 网站在线文档中也不可用。 到目前为止,
我是一名优秀的程序员,十分优秀!