Staff API PHP example

Discussion in 'Developing, APIs and extending' started by Bryan Gintz, Mar 15, 2012.

  1. Bryan Gintz

    Bryan Gintz New Member

    I am having some problems forming the CURL POST to do login authentication against my helpdesk. Does anyone have example code they could post?
  2. Ritu

    Ritu New Member

    $data = array('username' => $_POST['username'], 'password' => $_POST['password']);
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, '');
    curl_setopt ($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=".$_POST[username]."&password=".$_POST[password]);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
  3. Gurpreet Singh

    Gurpreet Singh Staff Member

    You can check this as well :

    $datatolog["username"] = utf8_encode("username");
    $datatolog["password"] = utf8_encode("password");
    $url = " ";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($datatolog,'','&'));
    curl_setopt($ch,CURLOPT_ENCODING , "gzip");
    $solution = curl_exec($ch);

Share This Page