Reputation: 1929
For some reason when I submit the form it says Message: json_encode() expects parameter 2 to be long, string given on this line of the controller and not sure why. Does anyone see what the issue is?
Controller
function forgot_password_submit()
{
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
if (!$this->form_validation->run())
{
$this->kow_auth->output('There was a problem submitting the form! Please refresh the window and try again!', FALSE);
return;
}
$user_data = $this->users->get_user_by_username($this->input->post('username'));
if ($user_data === NULL)
{
$this->kow_auth->output('User does not exist in the database!', FALSE);
return;
}
$already_sent_password = (isset($user_data->new_password_key) && isset($user_data->new_password_requested));
if ($already_sent_password)
{
$this->kow_auth->output('Check your email for your temporary password!');
return;
}
if (!strtotime($user_data->new_password_requested) <= (time() - 172800))
{
$this->kow_auth->output('You have to wait 2 days before a new temp password can be emailed!', FALSE);
}
else
{
if ($this->kow_auth->forgot_password($this->input->post('username')))
{
$this->kow_auth->send_email('forgot_password', 'KOW Manager Forgot Password Email', $user_data);
$this->kow_auth->output('A temporary password has been emailed to you!');
}
else
{
$this->kow_auth->output('A temporary password could not be created for you!', FALSE);
}
}
}
kow_auth library
/**
* Generate output message
*
* @param string
* @return object
*/
function output($message, $success = TRUE)
{
$status = $success ? array('succes' => 'yes') : array('error' => 'yes');
echo json_encode($status, $message);
}
Upvotes: 0
Views: 601
Reputation: 522597
Well yes, the second parameter to json_encode
is supposed to be a bitmask of options, not a message. You can only encode one thing at a time, not a string and an array. Maybe you want something like json_encode(array($status, $message))
?
Upvotes: 2