如何在具有有限控制的共享主机上 php 代码 运行 中 watch/log 变量值?
How to watch/log variable value in a php code running on a shared host with limited contorl?
我正在调试安装在我的共享主机上的 php 系统(linux、cpanel、php 5.2)。我发现我遇到的问题是 php 文件中的一个函数。我想看看执行时该文件中所有变量的值是多少。
我试过 mail() 将变量值邮寄给自己,但没有成功。
我还尝试了错误功能,以便我可以读取错误日志文件,但我的主机中没有创建文件,或者错误文件中没有消息。我尝试了以下错误函数。
error_log("Err!", 0);
error_log("Err", 1,"operator@example.com");
error_log("Err", 3, "/my-errors.log");
我正在使用来自 namecheap 的共享主机,它不提供所有功能,也不提供对所有日志的访问。
知道如何检查该特定函数中发生的事情,以及执行时其中变量的值是多少吗?
非常感谢
问题函数如下,如果有帮助:
/**
* Reset a user's password
* @param $args array first param contains the username of the user whose password is to be reset
*/
function resetPassword($args, &$request) {
$this->validate();
$this->setupTemplate($request);
$site =& $request->getSite();
$oneStepReset = $site->getSetting('oneStepReset') ? true : false;
$username = isset($args[0]) ? $args[0] : null;
$userDao =& DAORegistry::getDAO('UserDAO');
$confirmHash = $request->getUserVar('confirm');
if ($username == null || ($user =& $userDao->getByUsername($username)) == null) {
$request->redirect(null, null, 'lostPassword');
}
$templateMgr =& TemplateManager::getManager();
$hash = Validation::generatePasswordResetHash($user->getId());
if ($hash == false || $confirmHash != $hash) {
$templateMgr->assign('errorMsg', 'user.login.lostPassword.invalidHash');
$templateMgr->assign('backLink', $request->url(null, null, 'lostPassword'));
$templateMgr->assign('backLinkLabel', 'user.login.resetPassword');
$templateMgr->display('common/error.tpl');
} else if (!$oneStepReset) {
// Reset password
$newPassword = Validation::generatePassword();
if ($user->getAuthId()) {
$authDao =& DAORegistry::getDAO('AuthSourceDAO');
$auth =& $authDao->getPlugin($user->getAuthId());
}
if (isset($auth)) {
$auth->doSetUserPassword($user->getUsername(), $newPassword);
$user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
} else {
$user->setPassword(Validation::encryptCredentials($user->getUsername(), $newPassword));
}
$user->setMustChangePassword(1);
$userDao->updateObject($user);
// Send email with new password
import('classes.mail.MailTemplate');
$mail = new MailTemplate('PASSWORD_RESET');
$this->_setMailFrom($request, $mail, $site);
$mail->assignParams(array(
'username' => $user->getUsername(),
'password' => $newPassword,
'siteTitle' => $site->getLocalizedTitle()
));
$mail->addRecipient($user->getEmail(), $user->getFullName());
$mail->send();
$templateMgr->assign('pageTitle', 'user.login.resetPassword');
$templateMgr->assign('message', 'user.login.lostPassword.passwordSent');
$templateMgr->assign('backLink', $request->url(null, $request->getRequestedPage()));
$templateMgr->assign('backLinkLabel', 'user.login');
$templateMgr->display('common/message.tpl');
} else {
import('classes.user.form.LoginChangePasswordForm');
$passwordForm = new LoginChangePasswordForm($confirmHash);
$passwordForm->initData();
if (isset($args[0])) {
$passwordForm->setData('username', $username);
}
$passwordForm->display();
}
}
我会像这样在函数末尾使用 var_dump。将为您提供所有数据,如果您将其包装在标签中,它看起来会更好。
echo "<pre>";
var_dump(get_defined_vars());
echo "</pre>";
或者对您的 $this 变量执行此操作
我正在调试安装在我的共享主机上的 php 系统(linux、cpanel、php 5.2)。我发现我遇到的问题是 php 文件中的一个函数。我想看看执行时该文件中所有变量的值是多少。
我试过 mail() 将变量值邮寄给自己,但没有成功。 我还尝试了错误功能,以便我可以读取错误日志文件,但我的主机中没有创建文件,或者错误文件中没有消息。我尝试了以下错误函数。
error_log("Err!", 0);
error_log("Err", 1,"operator@example.com");
error_log("Err", 3, "/my-errors.log");
我正在使用来自 namecheap 的共享主机,它不提供所有功能,也不提供对所有日志的访问。
知道如何检查该特定函数中发生的事情,以及执行时其中变量的值是多少吗?
非常感谢
问题函数如下,如果有帮助:
/**
* Reset a user's password
* @param $args array first param contains the username of the user whose password is to be reset
*/
function resetPassword($args, &$request) {
$this->validate();
$this->setupTemplate($request);
$site =& $request->getSite();
$oneStepReset = $site->getSetting('oneStepReset') ? true : false;
$username = isset($args[0]) ? $args[0] : null;
$userDao =& DAORegistry::getDAO('UserDAO');
$confirmHash = $request->getUserVar('confirm');
if ($username == null || ($user =& $userDao->getByUsername($username)) == null) {
$request->redirect(null, null, 'lostPassword');
}
$templateMgr =& TemplateManager::getManager();
$hash = Validation::generatePasswordResetHash($user->getId());
if ($hash == false || $confirmHash != $hash) {
$templateMgr->assign('errorMsg', 'user.login.lostPassword.invalidHash');
$templateMgr->assign('backLink', $request->url(null, null, 'lostPassword'));
$templateMgr->assign('backLinkLabel', 'user.login.resetPassword');
$templateMgr->display('common/error.tpl');
} else if (!$oneStepReset) {
// Reset password
$newPassword = Validation::generatePassword();
if ($user->getAuthId()) {
$authDao =& DAORegistry::getDAO('AuthSourceDAO');
$auth =& $authDao->getPlugin($user->getAuthId());
}
if (isset($auth)) {
$auth->doSetUserPassword($user->getUsername(), $newPassword);
$user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
} else {
$user->setPassword(Validation::encryptCredentials($user->getUsername(), $newPassword));
}
$user->setMustChangePassword(1);
$userDao->updateObject($user);
// Send email with new password
import('classes.mail.MailTemplate');
$mail = new MailTemplate('PASSWORD_RESET');
$this->_setMailFrom($request, $mail, $site);
$mail->assignParams(array(
'username' => $user->getUsername(),
'password' => $newPassword,
'siteTitle' => $site->getLocalizedTitle()
));
$mail->addRecipient($user->getEmail(), $user->getFullName());
$mail->send();
$templateMgr->assign('pageTitle', 'user.login.resetPassword');
$templateMgr->assign('message', 'user.login.lostPassword.passwordSent');
$templateMgr->assign('backLink', $request->url(null, $request->getRequestedPage()));
$templateMgr->assign('backLinkLabel', 'user.login');
$templateMgr->display('common/message.tpl');
} else {
import('classes.user.form.LoginChangePasswordForm');
$passwordForm = new LoginChangePasswordForm($confirmHash);
$passwordForm->initData();
if (isset($args[0])) {
$passwordForm->setData('username', $username);
}
$passwordForm->display();
}
}
我会像这样在函数末尾使用 var_dump。将为您提供所有数据,如果您将其包装在标签中,它看起来会更好。
echo "<pre>";
var_dump(get_defined_vars());
echo "</pre>";
或者对您的 $this 变量执行此操作