I am debugging a php system installed on my shared-host (linux, cpanel, php 5.2). I found that the problem I am experience is within one function in a php file. I want to see what are the values of all the variables in that file when it is executed.
I tried mail() to mail the variable values to myself but it did not work. I also tried error function so that I can read the error log file, but no file was created in my host, or no message was in the error files. I tried following error functions.
error_log("Err!", 0);
error_log("Err", 1,"operator@example.com");
error_log("Err", 3, "/my-errors.log");
I am using a shared host from namecheap, which does not provide all the functionalities, nor access to all logs.
any idea how I can inspect what is going on in that specific function, and what are the values of the variable in it in the execution time?
many thanks
The function in question is as follows, if it helps:
/**
* 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();
}
}
I would just use a var_dump at the end of the function like this. Will give you all of the data, if you wrap it in tags it looks nicer.
echo "<pre>";
var_dump(get_defined_vars());
echo "</pre>";
Or do it to your $this var.