I'm new to php & cUrl's so I was wondering if someone knows how to get the following command executed using php.
curl "http://www.mywebsite.com/index.php?action=confirm" -H "Origin: http://www.mywebsite.com" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" -H "Cache-Control: max-age=0" -H "Referer: http://www.mywebsite.com/index.php?action=confirm" -H "Connection: keep-alive" --data "confirmed=yes&id=14&from=&to=TestPerson" --compressed
Thanks in advance and sorry if this beginner stuff. I'm just trying to learn
Rewrite like this..
<?php
$ch = curl_init();
$curlconf = array(
CURLOPT_URL => "http://www.mywebsite.com/index.php?action=confirm",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => array(
'confirmed' => 'yes',
'id' => 14,
'from'=>'',
'to'=>'TestPerson',
)
);
curl_setopt_array($ch, $curlconf);
$result = curl_exec($ch);
echo $result;
curl_close($ch);
You have a PHP extension for that : http://www.php.net/manual/fr/curl.examples-basic.php
Related
I have nn.sh
#/bin/sh
cd /var/www/html
/usr/bin/curl 'https://web-api.wtnnip.com/app' \
-H 'authority: web-api.wtnnip.com' \
-H 'accept: */*' \
-H 'accept-language: ro-RO,ro;q=0.9,en-US;q=0.8,en;q=0.7' \
-H 'content-type: application/json' \
-H 'origin: https://www.wtnnip.com' \
-H 'referer: https://www.wtnnip.com/ro-RO/non-professional' \
-H 'sec-ch-ua: "Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "Linux"' \
-H 'sec-fetch-dest: empty' \
-H 'sec-fetch-mode: cors' \
-H 'sec-fetch-site: same-site' \
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36' \
--compressed
If I execute the file is working fine. If I copy cURL command and run in terminal, is working fine. Working fine means I receive the json collection.
But if I set crontab to run this file, or I run the file from PHP with exec or passthru I receive this error:
{"errors" : [ {
"message" : "Invalid JSON payload in GraphQLAuth POST request.",
"errorType" : "MalformedHttpRequestException"
} ]
}
I also try to write a code and use the cURL directly from PHP, but I receive the same error.
How can I run this from cron or php? Thanks!
LE:
I use Debian 11, PHP 7.4 and cURL 7.74
I have bash as shell, I try with #/bin/bash as well
SOLVED
#!/bin/bash in first line
I forgot the exclamation mark.
Thanks to Ulrich Eckhardt for light!
#!/bin/sh
cd /var/www/html || exit
If you want to try PHP, Try this:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://web-api.wtnnip.com/app');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'authority' => 'web-api.wtnnip.com',
'accept' => '*/*',
'accept-language' => 'ro-RO,ro;q=0.9,en-US;q=0.8,en;q=0.7',
'content-type' => 'application/json',
'origin' => 'https://www.wtnnip.com',
'referer' => 'https://www.wtnnip.com/ro-RO/non-professional',
'sec-ch-ua' => '"Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"',
'sec-ch-ua-mobile' => '?0',
'sec-ch-ua-platform' => '"Linux"',
'sec-fetch-dest' => 'empty',
'sec-fetch-mode' => 'cors',
'sec-fetch-site' => 'same-site',
'user-agent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36',
'Accept-Encoding' => 'gzip',
]);
$response = curl_exec($ch);
curl_close($ch);
I was trying to get html response using PHP but always get something like this
screenshot [picture hidden from post due to binary characters]
<?php
$header_request = array (
"accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-encoding: gzip",
"accept-language: id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
"cookie: csrf_cookie_name=9316014c9d7860019da66a78edfaf926; _data_pop=115-1_274-1; ci_session=607f0be4e56b8b08ee2398b892f115c9e660192e; _data_cpc=1-2_15-2_190-4",
"referer: https://ptc4btc.com/",
"user-agent: Mozilla/5.0 (Linux; Android 7.0; Moto C Plus) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.56 Mobile Safari/537.36",
"upgrade-insecure-requests: 1"
);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "https://ptc4btc.com/dashboard",
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HTTPHEADER => $header_request,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 2,
));
$exec = curl_exec($ch);
echo($exec);
curl_close($exec);
You said you were willing to accept gzip data with accept-encoding: gzip in the headers. So decode it:
echo gzdecode($exec);
I'm trying to make a simple curl post request using PHP code snippet from Postman. But when I'm trying to run it I get the following error: "OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054"
In postman the request is working fine and I do get the json results.
Here's an inline link for postman header
and the postman body
My php code is the following:
$curl = curl_init();
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.oglasnik.hr/ajax/getNearBy",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 500,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"classifiedId\"\r\n\r\n3996266\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"bounds\"\r\n\r\n{\"east\":16.00793838500977,\"west\":15.977039337158205,\"north\":45.78652940999985,\"south\":45.773958941535355}\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"Accept: application/json, text/javascript, */*; q=0.01",
"Accept-Encoding: gzip, deflate, br",
"Accept-Language: en-US,en;q=0.9",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Length: 384",
"Content-Type: application/x-www-form-urlencoded",
"Cookie: cookieconsent_status=allow; ogl_visits^[0^]=a5cbwGRWU7YEC1LP6tKOVOzf6GIZzyU7dbry64BfNak4xygExIAj^%^2FkGWQ5azKqmznEHJVCF4ZfufdAaCugfPjPi8vX7CB8Gs^%^2F3OdX5RVvYjyfWKHUHboChkYfbURk6Ly",
"Host: www.oglasnik.hr",
"Origin: https://www.oglasnik.hr",
"Postman-Token: 60eebbd3-ed26-4aed-ae32-f190353ce333,aa32ad1d-55c6-4fa6-928e-3309a497c36a",
"Referer: https://www.oglasnik.hr/stanovi-najam/novi-zagreb-bundek-2-sobni-stan-55-m2-oglas-3996266",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
"X-Requested-With: XMLHttpRequest",
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
UPDATE:
With the tip from #Andrew I changed the CURLOPT_HTTPHEADER to:
CURLOPT_HTTPHEADER => array(
"Accept: application/json, text/javascript, */*; q=0.01",
"Accept-Encoding: gzip, deflate, br",
"Accept-Language: en-US,en;q=0.9",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Type: application/x-www-form-urlencoded",
"Cookie: cookieconsent_status=allow; ogl_visits^[0^]=a5cbwGRWU7YEC1LP6tKOVOzf6GIZzyU7dbry64BfNak4xygExIAj^%^2FkGWQ5azKqmznEHJVCF4ZfufdAaCugfPjPi8vX7CB8Gs^%^2F3OdX5RVvYjyfWKHUHboChkYfbURk6Ly",
"Host: www.oglasnik.hr",
"Origin: https://www.oglasnik.hr",
"Referer: https://www.oglasnik.hr/stanovi-najam/novi-zagreb-bundek-2-sobni-stan-55-m2-oglas-3996266",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
"X-Requested-With: XMLHttpRequest",
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
)
And i'm getting the response! Unfortunately its only
{
"status": false
}
As it looks like I'm sending my post parameters wrong. Problem is that I need to send one integer parameter and one string as json, currently trying like this:
$bounds =
[
"east" => 16.00793838500977,
"west" =>15.977039337158205,
"north" =>45.78652940999985,
"south" =>45.773958941535355
];
$params = [
"classifiedId" => 3996266, "bounds" => json_encode($bounds)
];
and adding this parameter in curl_setopt_array:
CURLOPT_POSTFIELDS => $params
Final update:
It worked! As #Andrew stated in the comments it worked using:
CURLOPT_POSTFIELDS => http_build_query($params)
so the final header is:
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.oglasnik.hr/ajax/getNearBy",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query($params),
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPHEADER => array(
"Accept: application/json, text/javascript, */*; q=0.01",
"Accept-Encoding: gzip, deflate, br",
"Accept-Language: en-US,en;q=0.9",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Type: application/x-www-form-urlencoded",
"Cookie: cookieconsent_status=allow; ogl_visits^[0^]=a5cbwGRWU7YEC1LP6tKOVOzf6GIZzyU7dbry64BfNak4xygExIAj^%^2FkGWQ5azKqmznEHJVCF4ZfufdAaCugfPjPi8vX7CB8Gs^%^2F3OdX5RVvYjyfWKHUHboChkYfbURk6Ly",
"Host: www.oglasnik.hr",
"Origin: https://www.oglasnik.hr",
"Referer: https://www.oglasnik.hr/stanovi-najam/novi-zagreb-bundek-2-sobni-stan-55-m2-oglas-3996266",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
"X-Requested-With: XMLHttpRequest",
"cache-control: no-cache",
"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
I created a POST request on POSTMAN, it work great. But when I export header and form body in PHP cURL code and execute it with PHP CLI, the server does not show me data asked in my form.
Thereafter the PHP cURL exported with POSTMAN :
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://renovation-info-service.gouv.fr/trouvez-un-professionnel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "all%5Bcols-1%5D%5Bcode_postal%5D=03&all%5Bcols-1%5D%5Bcommune%5D=03&all%5Brayon%5D=5&all%5Bdomaine_travaux%5D=30&op=Localiser%2Bdes%2Bentreprises&form_build_id=form-48ViCRy2vxhZBo452cPiRi22VR7K2mZ5ZUwzR-tlO3U&form_id=front_office__locate_all_entreprise_form",
CURLOPT_HTTPHEADER => array(
"accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"accept-encoding: gzip, deflate",
"accept-language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3",
"cache-control: no-cache",
"connection: keep-alive",
"content-length: 253",
"content-type: application/x-www-form-urlencoded",
"cookie: UUID=3ab96f55-1e99-d7c4-39a9-59345773b4ca; has_js=1; _ga=GA1.3.1779497884.1533297982; _gid=GA1.3.1474901001.1533297982; _gat=1",
"host: renovation-info-service.gouv.fr",
"postman-token: 570c2dd8-8289-dacd-db57-dcb0d107ea29",
"referer: http://renovation-info-service.gouv.fr/trouvez-un-professionnel",
"upgrade-insecure-requests: 1",
"user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
Thank you for your help ! And sorry with my bad english ^^'
POSTMAN answer is a html code with data asked in POST request. PHP cURL answer is a html code without data asked in POST request.
So, I was inspecting the network while I'm uploading an JPG image.
A copy as a curl command :
curl "https://admin-official.line.me/11702069/home/api/objects" -H "Origin: https://admin-official.line.me" -H "Accept-Encoding: gzip, deflate, br" -H "Accept-Language: en-US,en;q=0.9,id;q=0.8,de-DE;q=0.7,de;q=0.6" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36" -H "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBv1B9k1i89zlgjnA" -H "Accept: */*" -H "Referer: https://admin-official.line.me/11702069/home/send/" -H "Cookie: tzoffset=-420; _trmccid=6b030cba93d9db09; _ga=GA1.2.1058855825.1526457491; _gid=GA1.2.814129237.1526457491; ldsuid=CiDum1r75zWBJ3f7oLqRAg==; _trmcdisabled2=-1; _trmcuser=^{^\^"id^\^":^\^"^\^"^}; _ga=GA1.3.1058855825.1526457491; _gid=GA1.3.814129237.1526457491; plack_session_localaccount=XXX; minesota=XXX; minesota2=XXX-jdT5f_x10ov7Re12NliQw_zFyIe9osY4oOOc2Rxdy1gMyBhXbKdPmnpA2LHB9VhvlqlL_4hkeSNQK5SgU; plack_session=6cd2e4790ae9990303ea54f7f35b305fba801dc0; _trmcsession=^{^\^"id^\^":^\^"b8ba0724^\^",^\^"path^\^":^\^"/11702069/home/send/^\^",^\^"query^\^":^\^"^\^",^\^"time^\^":1526735963213,^\^"_dice^\^":0.09452730791211028^}; __try__=1526737592637; _trmcpage=/11702069/home/send/" -H "Connection: keep-alive" --data-binary ^"------WebKitFormBoundaryBv1B9k1i89zlgjnA^
Content-Disposition: form-data; name=^\^"file^\^"; filename=^\^"alpen.jpg^\^"^
Content-Type: image/jpeg^
^
^
------WebKitFormBoundaryBv1B9k1i89zlgjnA^
Content-Disposition: form-data; name=^\^"csrf_token^\^"^
^
vJiSf8AZPpAvqCp0JQtrNOMgrZRtrDpa1TEHbYLz^
------WebKitFormBoundaryBv1B9k1i89zlgjnA--^
^" --compressed
I've never seen this before, i'm not an expert at curl. But I'm using curl to PHP coverter, but it's not working in this case.
EDIT : here's what I've tried.
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://admin-official.line.me/11702069/home/api/objects");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => "#".realpath('test.jpg'), "csrf_token" => $split2[0]));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = "Origin: https://admin-official.line.me";
$headers[] = "Accept-Encoding: gzip, deflate, br";
$headers[] = "Accept-Language: en-US,en;q=0.9,id;q=0.8,de-DE;q=0.7,de;q=0.6";
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36";
$headers[] = "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBv1B9k1i89zlgjnA";
$headers[] = "Accept: */*";
$headers[] = "Referer: https://admin-official.line.me/11702069/home/send/";
$headers[] = 'Cookie: tzoffset=-420; _trmccid=6b030cba93d9db09; _ga=GA1.2.1058855825.1526457491; _gid=GA1.2.814129237.1526457491; ldsuid=CiDum1r75zWBJ3f7oLqRAg==; _trmcdisabled2=-1; _trmcuser={"id":""}; _ga=GA1.3.1058855825.1526457491; _gid=GA1.3.814129237.1526457491; plack_session_localaccount=XXX; minesota=XXX; minesota2=XXX; plack_session=XXX; _trmcsession={"id":"b8ba0724","path":"/11702069/home/send/","query":"","time":1526735963213,"_dice":0.09452730791211028}; __try__=1526737592637; _trmcpage=/11702069/home/send/';
$headers[] = "Connection: keep-alive";
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo $result;
?>
the "request payload" is the request body. a HTTP request is split into 2 parts, the headers, and the body (and Chrome calls the body for the request payload here, not sure if that's an official name, or just the whim of a chromium dev)
anyway, you're using the # method, which was discouraged as of PHP 5.5, disabled-by-default in php 5.6, and completely removed in PHP7.
use CURLFile instead, eg:
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
"file" => new CURLFile('test.jpg'),
"csrf_token" => $split2[0]
));
also, don't set the Accept-Encoding header manually. you specify gzip, deflate, br, and curl doesn't support br, and depending on how libcurl was compiled, might not even support gzip/deflate (although it usually does), remove that.
also, set CURLOPT_ENCODING to emptystring, and curl will list all encodings it was built to support (which is usually gzip and deflate, but is not guaranteed to be)
also, when using the # or CURLFile method, don't set the Content-Type header manually, because if curl's boundary doesn't match what you set in the Content-Type header, the server won't be able to read the request properly. curl will set this header for you, if you don't override it, so don't.
Figure it out using Postman.
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://admin-official.line.me/11702069/home/api/objects",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array(
"csrf_token" => $split2[0],
"file" => new CURLFile("test.jpg")
),
//CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"csrf_token\"\r\n\r\nETukCyg_-OM72cZ0MuAyunvvy4cb8Cx2QqoP41T7\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
CURLOPT_HTTPHEADER => array(
"Accept: */*",
"Accept-Encoding: gzip, deflate, br",
"Accept-Language: en-US,en;q=0.9,id;q=0.8,de-DE;q=0.7,de;q=0.6",
"Cache-Control: no-cache",
"Connection: keep-alive",
"Content-Type: multipart/form-data",
"Cookie: tzoffset=-420; _trmccid=6b030cba93d9db09; _ga=GA1.2.1058855825.1526457491; _gid=GA1.2.814129237.1526457491; ldsuid=CiDum1r75zWBJ3f7oLqRAg==; _trmcdisabled2=-1; _trmcuser=^{^\^id^^:^\^^^^}; _ga=GA1.3.1058855825.1526457491; _gid=GA1.3.814129237.1526457491; plack_session_localaccount=COOKIE; minesota=COOKIE; minesota2=COOKIE; _trmcsession=^{^\^id^^:^\^36b6efe6^^,^\^path^^:^\^/11702069/home/send/^^,^\^query^^:^\^^^,^\^time^^:1526880852499,^\^_dice^^:0.4099096438552394^}; plack_session=519cce226206bd15cba86f2153c9dc91a56df4fb; _trmcpage=/11702069/home/send/; __try__=1526881572577",
"Origin: https://admin-official.line.me",
"Postman-Token: 8b9dc9c8-166a-4c50-93c4-b16ca72d72dc",
"Referer: https://admin-official.line.me/11702069/home/send/",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
//"content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
),
));
curl_setopt($curl, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}