Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal 7 - Update a user with services using PHP Curl
    primarykey
    data
    text
    <p>I'm using Drupal 7 and the services module and I'm trying to update a user profile using PHP &amp; Curl. Do I always have to login before sending a "PUT/update" ?</p> <p>This is my code so far :</p> <pre><code>&lt;?php // REST Server URL $request_url = 'http://mywebsite/end/user/login'; // User data $user_data = array( 'username' =&gt; 'user2', 'password' =&gt; 'pass1', ); // cURL $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $request_url); curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($user_data)); // Set POST data curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); $response = curl_exec($curl); print $response; $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); // Check if login was successful if ($http_code == 200) { // Convert json response as array $logged_user = json_decode($response); } else { // Get error msg $http_message = curl_error($curl); die($http_message); } print_r($logged_user); // REST Server URL $request_url = 'http://mywebsite.com/end/user/8&amp;XDEBUG_SESSION_START=netbeans-xdebug'; $user_data = array('current_pass' =&gt; 'pass1', 'pass' =&gt; 'pass2'); // Define cookie session $cookie_session = $logged_user-&gt;session_name . '=' . $logged_user-&gt;sessid; // cURL $curl = curl_init($request_url); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-type: application/json')); // Accept JSON response curl_setopt($curl, CURLOPT_PUT, TRUE); curl_setopt($curl, CURLOPT_HEADER, TRUE); // FALSE); // Ask to not return Header curl_setopt($curl, CURLOPT_COOKIE, "$cookie_session"); // use the previously saved session curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_FAILONERROR, TRUE); // Emulate file. $serialize_args = json_encode($user_data); $putData = fopen('php://temp', 'rw+'); fwrite($putData, $serialize_args); fseek($putData, 0); curl_setopt($curl, CURLOPT_INFILE, $putData); curl_setopt($curl, CURLOPT_INFILESIZE, drupal_strlen($serialize_args)); $response = curl_exec($curl); $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); // Check if login was successful $ret; if ($http_code == 200) { // Convert json response as array $ret = json_decode($response); } else { // Get error msg $http_message = curl_error($curl); die($http_message); } print_r($ret); curl_close($curl); } ?&gt; </code></pre> <p>What am I missing here? Nothing happens to my profile.</p> <p>Any answer is welcomed!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload