groomfedmek
New Member
Im signing in to my website and uploading a node remotely.The signing in works, I get the cookies and I can post a node to Drupal BUT it still says the post was made my an "anonymous" user.What is wrong with my code? ( The PHP-file and txt-file is server side)\[code\]<?php$login= "user5";$pass = "pass2";$url="http://mywebpage.com";$cookie="session_cookie.txt";$title="title of the post";$body="body of the post";$user_data = http://stackoverflow.com/questions/15846941/http_build_query($user_data);// cURL$curl = curl_init($request_url);curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json')); // Accept JSON responsecurl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POSTcurl_setopt($curl, CURLOPT_POSTFIELDS, $user_data); // Set POST datacurl_setopt($curl, CURLOPT_HEADER, FALSE); // Ask to not return Headercurl_setopt($curl, CURLOPT_USERAGENT, 'PHP script');curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie);curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie);curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);$response = curl_exec($curl);$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, true); print_r ($logged_user['sessid']); print_r ("="); print_r ($logged_user['session_name']); $ye = $logged_user['session_name']; $yes = '='; $yesa = $logged_user['sessid'];}else { // Get error msg $http_message = curl_error($curl); die($http_message);}$cookie_session = $ye . $yes . $yesa;print_r($cookie_session);//Token$ch = curl_init();curl_setopt($ch, CURLOPT_HEADER, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);curl_setopt($ch, CURLOPT_COOKIE, "$cookie_session"); curl_setopt($ch, CURLOPT_URL,"$url/endpoint/node/");$buf3 = curl_exec ($ch);curl_close ($ch);// find form tokenpreg_match('@name="form_token" value="http://stackoverflow.com/questions/15846941/([^"]*)"@',$buf3,$matches);$token=$matches[1];//Post$ch = curl_init();//curl_setopt($ch, CURLOPT_HEADER, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);curl_setopt($ch, CURLOPT_COOKIE, "$cookie_session"); curl_setopt($ch, CURLOPT_URL,"$url/endpoint/node/");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, "title=test&body[und][0][value]=dfff&type=page&uid=1&status=1&promote=1&revision=0&comment=1&preview=&name=$login&op=Submit&form_id=page_node_form&form_token=$token");$buf2 = curl_exec ($ch); $headers = curl_getinfo($ch); $url3=$headers['url'];curl_close ($ch);?>\[/code\]Any help would save my skin! Been trying for hours