SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Command line Curl to Php curl code problem

    Command line Curl which is working properly is :

    curl --data username=ekansh&domain=siteURL&password=mypass
    http://siteURL:8090/add-user -k -v -u apiuser:XXXXXXX


    And i have tried below code for convert it in PHP CURL CODE:

    $fields = array('domain' => 'SiteUrl:8090','password' => 'mypass','username' => 'Ekansh');

    $data=array(CURLOPT_POST => 1,CURLOPT_HEADER => 0,CURLOPT_URL =>
    'SiteUrl:8090/add-user ',CURLOPT_FRESH_CONNECT => 1,CURLOPT_RETURNTRANSFER => 1,CURLOPT_FORBID_REUSE =>
    1,CURLOPT_TIMEOUT => 4,CURLOPT_POSTFIELDS => $fields,CURLOPT_SSL_VERIFYPEER => FALSE,CURLOPT_USERPWD => 'apiuser:XXXXXXX',CURLOPT_VERBOSE=>TRUE);

    $ch = curl_init();
    curl_setopt_array($ch,$data);
    $result=curl_exec($ch);
    curl_close($ch);

    But above code is not working. what i am done wrong in code?

  2. #2
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    664
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    1. Consider adding some [PHP ][/PHP ] tags around the code in your question to make it a bit easier to read.
    2. Is it generating an error? Not returning? Returning the wrong values? A hint might be useful.
    3. Make a simple curl php script that just downloads a site or something. This will help to verify if you have curl extension loaded. You can also check phpinfo.

  3. #3
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,079
    Mentioned
    53 Post(s)
    Tagged
    0 Thread(s)
    Whats the $result variable look like? Also, echo out curl_error (http://php.net/manual/en/function.curl-error.php)


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •