最近,我发现这个名为usercake (http://usercake.com/)的小用户类脚本具有所有的基本功能,并且似乎工作得很好。
My problem:第一个用户可以很好地添加到数据库中,但是在那之后它就不能工作了。显然,有一些轻微的错误,我没有弄清楚(我不太了解oop )。没有错误发生(我能看到),电子邮件被发送出去。
我已经安装了多个相同命运的地方。我想修复它,因为使用这个脚本可以节省很多重新发明轮子的时间。
下面是我拥有它的URL:http://rawcomposition.com/birding/loggedin/register.php这里是一旦所有内容都被验证就会被调用的函数:
public function userCakeAddUser()
{
global $db,$emailActivation,$websiteUrl,$db_table_prefix;
//Prevent this function being called if there were construction errors
if($this->status)
{
//Construct a secure hash for the plain text password
$secure_pass = generateHash($this->clean_password);
//Construct a unique activation token
$this->activation_token = generateActivationToken();
//Do we need to send out an activation email?
if($emailActivation)
{
//User must activate their account first
$this->user_active = 0;
$mail = new userCakeMail();
//Build the activation message
$activation_message = lang("ACTIVATION_MESSAGE",array($websiteUrl,$this->activation_token));
//Define more if you want to build larger structures
$hooks = array(
"searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"),
"subjectStrs" => array($activation_message,$this->activation_token,$this->unclean_username)
);
/* Build the template - Optional, you can just use the sendMail function
Instead to pass a message. */
if(!$mail->newTemplateMsg("new-registration.txt",$hooks))
{
$this->mail_failure = true;
}
else
{
//Send the mail. Specify users email here and subject.
//SendMail can have a third parementer for message if you do not wish to build a template.
if(!$mail->sendMail($this->clean_email,"New User"))
{
$this->mail_failure = true;
}
}
}
else
{
//Instant account activation
$this->user_active = 1;
}
if(!$this->mail_failure)
{
//Insert the user into the database providing no errors have been found.
$sql = "INSERT INTO `".$db_table_prefix."Users` (
`Username`,
`Username_Clean`,
`Password`,
`Email`,
`ActivationToken`,
`LastActivationRequest`,
`LostPasswordRequest`,
`Active`,
`Group_ID`,
`SignUpDate`,
`LastSignIn`
)
VALUES (
'".$db->sql_escape($this->unclean_username)."',
'".$db->sql_escape($this->clean_username)."',
'".$secure_pass."',
'".$db->sql_escape($this->clean_email)."',
'".$this->activation_token."',
'".time()."',
'0',
'".$this->user_active."',
'1',
'".time()."',
'0'
)";
return $db->sql_query($sql);
}
}
}这是桌子的结构:
CREATE TABLE IF NOT EXISTS `userCake_Users` (
`User_ID` int(11) NOT NULL AUTO_INCREMENT,
`Username` varchar(150) NOT NULL,
`Name` varchar(100) NOT NULL,
`Username_Clean` varchar(150) NOT NULL,
`Password` varchar(225) NOT NULL,
`Email` varchar(150) NOT NULL,
`ActivationToken` varchar(225) NOT NULL,
`LastActivationRequest` int(11) NOT NULL,
`LostPasswordRequest` int(1) NOT NULL DEFAULT '0',
`Active` int(1) NOT NULL,
`Group_ID` int(11) NOT NULL,
`SignUpDate` int(11) NOT NULL,
`LastSignIn` int(11) NOT NULL,
PRIMARY KEY (`User_ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;发布于 2011-06-22 09:36:51
对我来说,在添加第一个用户之后,它没有添加更多的用户有两种可能:
首先,在创建第一个用户之后,将以下用户帐户的$this->mail_failure标志设置为TRUE。但是,这种情况不太可能发生,因为对于第一个用户成功运行的代码是相同的,因此没有理由让其他用户的标记为TRUE。
第二种可能性是,对于第二个用户帐户,$this->status是假的。如果为false,则userCakeAddUser()方法不会执行任何操作。此标志可能为假的原因是用户名或电子邮件地址已经存在。
您是否使用与第二个帐户的第一个帐户相同的用户名或电子邮件地址?我相信你一定不会使用相同的用户名,但可能使用相同的电子邮件地址。usercake类不允许相同的用户名或电子邮件地址。
希望这能有所帮助。
发布于 2011-06-22 23:03:19
我会用这个恶毒的代码做4件事:
1)启用error_reporting模式,以便在发生某事时可以看到:
error_reporting(E_ALL); 2)将此插入的sql 直接插入到dB中以确保其正常工作,并验证这段代码。如果sql请求有效,那么检查这些SQL请求的访问条件,如上文Abhay所说,
3)由于我们没有您的所有配置可用,猜测游戏是困难的。因此,我建议您为AI User_ID添加一个空字段。
$sql = "INSERT INTO `".$db_table_prefix."Users` (
`User_ID`, // Add this here
`Username`,
`Username_Clean`,
`Password`,
`Email`,
`ActivationToken`,
`LastActivationRequest`,
`LostPasswordRequest`,
`Active`,
`Group_ID`,
`SignUpDate`,
`LastSignIn`
)
VALUES (
NULL, // and that one
'".$db->sql_escape($this->unclean_username)."',
'".$db->sql_escape($this->clean_username)."',
'".$secure_pass."',
'".$db->sql_escape($this->clean_email)."',
'".$this->activation_token."',
'".time()."',
'0', // later, I would also try using an int for an int
'".$this->user_active."',
'1',
'".time()."',
'0'
)";4)使用OOP和PDO查找另一个编码更好的对象。
发布于 2011-06-22 06:27:23
您将名称指定为null,在Insert语句中,您的代码没有发送名称值,因此mysql将抛出一个异常,表示Name不能为NULL,请检查一次。
https://stackoverflow.com/questions/6347636
复制相似问题