Curl in codeigniter

2019-03-02 16:12发布

问题:

I want to use curl in my codeigniter application. But I am getting null array.

My code is like this:

$this->load->library('curl');
$url = "http://url/checkweb.php"; 
$post_data = array ( 
    "foo" => "bar", 
    "query" => "Nettuts", 
    "action" => "Submit" 
);
$output = $this->curl->simple_post($url, $post_data);

checkweb.php:

print_r($_POST);

now actually I want to pass current url and it will check that its in my private database and if it is there then its ok else it will redirect to google.com because my code can't be copied on other domain

回答1:

If you're using the cURL library, you should have this at the bare minimum.

$this->load->library('curl');
$url = "http://url/checkweb.php"; 
$post_data = array ( 
    "foo" => "bar", 
    "query" => "Nettuts", 
    "action" => "Submit" 
);
$output = $this->curl->simple_post($url, $post_data);


回答2:

URL passed to cURL should be absolute-full-with-domain.

Instead of:

$url = "url/checkweb.php"; 

try:

$url = "http://yourdomain.com/url/checkweb.php";