Hey How will send cookie with API request in php curl

$cookieValue = $_COOKIE['DesigntoolAuth'];
		//  Initiate curl
		$ch = curl_init();
		// Disable SSL verification
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_VERBOSE, true);
		$cookie_file = tempnam (sys_get_temp_dir(), 'cookie'); 
		echo $cookie_file; 
    // and set the cURL cookie jar and file

    if (!file_exists($cookie_file) || !is_writable($cookie_file)){
            echo 'Cookie file missing or not writable.';
            die;
    }

    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieValue);
/* make sure you provide FULL PATH to cookie files*/
		
		// Will return the response, if false it print the response
		
		// Set the url
		curl_setopt($ch, CURLOPT_URL,$url);
		// Execute
		$api_result=curl_exec($ch);
		// Closing
		curl_close($ch);
		$data = json_decode($api_result, true);
		//var_dump($data);
		$api_result = json_encode($data);
		//$count= count($api_result);
		echo $api_result;

I have written above code to get the details as per cookie send in request, but not getting the result

What website/ URL are you calling? Does the cookie need to be set by the website first to then be called with the cookie?

Scott

Hey s_molinari,

Cookies are getting created after login , and after that i need to send a API request for my Account with cookie in Get request, Directly i am using cookie value using L $cookieValue = $_COOKIE[‘DesigntoolAuth’];. but someone said u need to file up the cookies

So you are logging in with curl requests?

Scott

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.