【发布时间】:2017-10-24 12:19:58
【问题描述】:
在我的网站上,我在 cpanel 上使用 cron 作业。
我在控制器的构造区域中有以下代码,但它阻止了 cpanel cron 作业的工作。
if (!$this->input->is_cli_request()) {
show_error('Direct access is not allowed');
}
问题我需要上面的代码吗?如果我使用我的 cpanel cron 工作?我只是想让它更安全。
<?php
class Cron extends CI_Controller {
public function __construct() {
parent::__construct();
if (!$this->input->is_cli_request()) {
show_error('Direct access is not allowed');
}
$this->load->library('email');
$this->load->model('members_model');
}
public function message()
{
$admin_email = $this->config->item('email_host');
$admin_email_pass = $this->config->item('email_password');
$companyname = 'Riwaka';
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://mail.yourdomain.co.nz',
'smtp_port' => 465,
'smtp_user' => $admin_email,
'smtp_pass' => $admin_email_pass,
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->email->initialize($config);
$members = $this->members_model->get_approved_members_for_cron_job();
if ($members) {
foreach ($members as $member) {
if ($member['approved'] == '1' && $member['approved_email_sent'] == '0')
{
$this->email->set_newline("\r\n");
$this->email->clear();
$this->email->from($admin_email, 'Admin');
$this->email->to($member['email']);
$this->email->subject($companyname .' Account Approved');
$this->email->message('test');
$update = array(
'approved_email_sent' => '1',
);
$this->members_model->update_approve_email_send($member['email'], $update);
$this->email->send();
}
}
}
}
}
【问题讨论】:
标签: codeigniter