微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CI函数无法使用外部PHP脚本

我需要运行CI控制器>来自外部PHP脚本的方法..外部PHP脚本使用curl发送一些值

$url = 'http://domain.com/ci_system/billing/success';

$fields = array(
    'ammount' => $extra[0]['ammount'],
    'email' => $extra[0]['email'],
    'cemail' => $extra[0]['cemail'],
    'rcode' => $completeResponse->getResponseCode(),
    'message' => $completeResponse->getResponseText()
);
$post = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);

以上成功功能我必须发送电子邮件. curl将所有必需的数据发送到成功函数但是不起作用.当我手动触发此功能时,它的工作原理..

控制器>方法

$this->cart->destroy();
$ord = array(
    'online' => 1
);
$this->Billing_model->updateOrder($ord, $this->session->userdata('data_o_i'));
//send email to the client
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);

$this->email->from('noreply@zxzxzxz.com', 'Dsd Retail New Order');
$this->email->to($this->input->post('omail@gmail.com'));

$this->email->subject('You have a new message for yor order');
$this->email->message($this->input->post('email'));

解决方法:

首先检查您的操作是否正常工作,如果您从网址调用它,则会给您预期的行为.

我用ci3进行了以下设置.

主机

$cat /etc/hosts
127.0.0.1 ci3.local

Apache站点 – 可用

cat /etc/apache2/sites-available/ci3.conf

<VirtualHost *:80>
        ServerAdmin email@email.com
        ServerName ci3.local
    DocumentRoot /home/user/project/ci3

    ErrorLog ${APACHE_LOG_DIR}/ci3_error.log
        CustomLog ${APACHE_LOG_DIR}/ci3_access.log combined

    SetEnv APPLICATION_ENV "development"

    <Directory /home/user/project/ci3>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        Allow from all
    </Directory> 

</VirtualHost>

CI3 /的.htaccess

RewriteEngine on
RewriteCond $1 !^(index\.PHP|images|robots\.txt)
RewriteRule ^(.*)$/index.PHP/$1 [L]

CI3 /应用/配置/ routes.PHP文件

$route['billing/success'] = 'billing/success';

CI3 /应用/控制器/ Billing.PHP

<?PHP
class Billing extends CI_Controller {

    public function success()
    {
        log_message('debug', 'Billing.success');
        log_message('debug', $this->input->post('amount'));
    }
}

现在,如果我从浏览器请求http://ci3.local/billing/success,它会将以下输出记录到我的日志文件

DEBUG - 2015-12-07 08:47:34 --> UTF-8 Support Enabled
DEBUG - 2015-12-07 08:47:34 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2015-12-07 08:47:34 --> Billing.success
DEBUG - 2015-12-07 08:47:34 --> 
DEBUG - 2015-12-07 08:47:34 --> Total execution time: 0.0019

如何从终端呼叫它并检查它是否正常工作?

$curl --data "amount=200" http://ci3.local/billing/success

然后我应该看到我的日志条目,如下所示

DEBUG - 2015-12-07 08:49:38 --> UTF-8 Support Enabled
DEBUG - 2015-12-07 08:49:38 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2015-12-07 08:49:38 --> Billing.success
DEBUG - 2015-12-07 08:49:38 --> 200
DEBUG - 2015-12-07 08:49:38 --> Total execution time: 0.0021

如何通过http从CURL调用此操作?

CI3 / curl.PHP

<?PHP
$ch = curl_init();
$cURLconfig = array(
    CURLOPT_URL            => "http://ci3.local/billing/success",
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS     => array(
        'amount' => '300'
    )
);
curl_setopt_array($ch, $cURLconfig);
$result = curl_exec($ch);
curl_close($ch);

从终端调用curl.PHP

PHP5 curl.PHP

然后我应该看到我的日志条目,如下所示

DEBUG - 2015-12-07 08:53:41 --> UTF-8 Support Enabled
DEBUG - 2015-12-07 08:53:41 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2015-12-07 08:53:41 --> Billing.success
DEBUG - 2015-12-07 08:53:41 --> 300
DEBUG - 2015-12-07 08:53:41 --> Total execution time: 0.0021

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐