Use cookie saved by curl in stream_get_contents
up vote
0
down vote
favorite
I wanted to send POST request , Actually curl is 100ms slower than stream_get_contents, so i wanted to use the latter.
I have a cookie.txt saved by curl , how do i use that to my stream_get_contents function below.
function poster($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
My cookie.txt stored by curl looks like below
secure.domain.com FALSE / FALSE 0 InterSecure AyDzUp5AEKz0ErJYeJF2221lIA$$
#HttpOnly_secure.domain.com FALSE / TRUE 0 ASP.NET_SessionId eqyrgo545czouimlnqc223f0qyi
I tried something like
$header = array(
'Referer: https://secure.domain.com/IDirectTrading/customer/login.aspx',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.20 Safari/537.36',
'Cookie : InterSecure = AyDzUp5AEKz0ErJYeJF2221lIA$$;ASP.NET_SessionId = eqyrgo545czouimlnqc223f0qyi'
);
$CE = poster("https://secure.domain.com/Handler.ashx",$str,$header);
But cookie doesnt seems to work , Is there any way to parse cookie text file into array and use that into header ?
php curl file-get-contents
|
show 1 more comment
up vote
0
down vote
favorite
I wanted to send POST request , Actually curl is 100ms slower than stream_get_contents, so i wanted to use the latter.
I have a cookie.txt saved by curl , how do i use that to my stream_get_contents function below.
function poster($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
My cookie.txt stored by curl looks like below
secure.domain.com FALSE / FALSE 0 InterSecure AyDzUp5AEKz0ErJYeJF2221lIA$$
#HttpOnly_secure.domain.com FALSE / TRUE 0 ASP.NET_SessionId eqyrgo545czouimlnqc223f0qyi
I tried something like
$header = array(
'Referer: https://secure.domain.com/IDirectTrading/customer/login.aspx',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.20 Safari/537.36',
'Cookie : InterSecure = AyDzUp5AEKz0ErJYeJF2221lIA$$;ASP.NET_SessionId = eqyrgo545czouimlnqc223f0qyi'
);
$CE = poster("https://secure.domain.com/Handler.ashx",$str,$header);
But cookie doesnt seems to work , Is there any way to parse cookie text file into array and use that into header ?
php curl file-get-contents
"doesn't seem to work" doesn't give us a lot to go on. Does the extra header get sent at all with the request? Have you tried getting rid of all the extra whitespace in that line?
– miken32
Nov 7 at 19:03
doesn't seem to work - The page i request is logged out , cookie doesnt seem to work.. whereas if i send curl request with that cookie file , response is logged in
– Gracie williams
Nov 7 at 19:04
Ok, but again, "logged out" doesn't mean anything in the context of us looking at this code. Have you verified that the cookie header is getting sent with the request?
– miken32
Nov 7 at 19:10
how do i check if its sent ?
– Gracie williams
Nov 7 at 19:11
Hmm, not sure actually, if you don't have access to the server. Did you try formatting the cookie properly per my answer?
– miken32
Nov 7 at 19:15
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I wanted to send POST request , Actually curl is 100ms slower than stream_get_contents, so i wanted to use the latter.
I have a cookie.txt saved by curl , how do i use that to my stream_get_contents function below.
function poster($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
My cookie.txt stored by curl looks like below
secure.domain.com FALSE / FALSE 0 InterSecure AyDzUp5AEKz0ErJYeJF2221lIA$$
#HttpOnly_secure.domain.com FALSE / TRUE 0 ASP.NET_SessionId eqyrgo545czouimlnqc223f0qyi
I tried something like
$header = array(
'Referer: https://secure.domain.com/IDirectTrading/customer/login.aspx',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.20 Safari/537.36',
'Cookie : InterSecure = AyDzUp5AEKz0ErJYeJF2221lIA$$;ASP.NET_SessionId = eqyrgo545czouimlnqc223f0qyi'
);
$CE = poster("https://secure.domain.com/Handler.ashx",$str,$header);
But cookie doesnt seems to work , Is there any way to parse cookie text file into array and use that into header ?
php curl file-get-contents
I wanted to send POST request , Actually curl is 100ms slower than stream_get_contents, so i wanted to use the latter.
I have a cookie.txt saved by curl , how do i use that to my stream_get_contents function below.
function poster($url, $data, $optional_headers = null)
{
$params = array('http' => array(
'method' => 'POST',
'content' => $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
My cookie.txt stored by curl looks like below
secure.domain.com FALSE / FALSE 0 InterSecure AyDzUp5AEKz0ErJYeJF2221lIA$$
#HttpOnly_secure.domain.com FALSE / TRUE 0 ASP.NET_SessionId eqyrgo545czouimlnqc223f0qyi
I tried something like
$header = array(
'Referer: https://secure.domain.com/IDirectTrading/customer/login.aspx',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.20 Safari/537.36',
'Cookie : InterSecure = AyDzUp5AEKz0ErJYeJF2221lIA$$;ASP.NET_SessionId = eqyrgo545czouimlnqc223f0qyi'
);
$CE = poster("https://secure.domain.com/Handler.ashx",$str,$header);
But cookie doesnt seems to work , Is there any way to parse cookie text file into array and use that into header ?
php curl file-get-contents
php curl file-get-contents
edited Nov 7 at 19:19
miken32
22.7k84671
22.7k84671
asked Nov 7 at 18:51
Gracie williams
558
558
"doesn't seem to work" doesn't give us a lot to go on. Does the extra header get sent at all with the request? Have you tried getting rid of all the extra whitespace in that line?
– miken32
Nov 7 at 19:03
doesn't seem to work - The page i request is logged out , cookie doesnt seem to work.. whereas if i send curl request with that cookie file , response is logged in
– Gracie williams
Nov 7 at 19:04
Ok, but again, "logged out" doesn't mean anything in the context of us looking at this code. Have you verified that the cookie header is getting sent with the request?
– miken32
Nov 7 at 19:10
how do i check if its sent ?
– Gracie williams
Nov 7 at 19:11
Hmm, not sure actually, if you don't have access to the server. Did you try formatting the cookie properly per my answer?
– miken32
Nov 7 at 19:15
|
show 1 more comment
"doesn't seem to work" doesn't give us a lot to go on. Does the extra header get sent at all with the request? Have you tried getting rid of all the extra whitespace in that line?
– miken32
Nov 7 at 19:03
doesn't seem to work - The page i request is logged out , cookie doesnt seem to work.. whereas if i send curl request with that cookie file , response is logged in
– Gracie williams
Nov 7 at 19:04
Ok, but again, "logged out" doesn't mean anything in the context of us looking at this code. Have you verified that the cookie header is getting sent with the request?
– miken32
Nov 7 at 19:10
how do i check if its sent ?
– Gracie williams
Nov 7 at 19:11
Hmm, not sure actually, if you don't have access to the server. Did you try formatting the cookie properly per my answer?
– miken32
Nov 7 at 19:15
"doesn't seem to work" doesn't give us a lot to go on. Does the extra header get sent at all with the request? Have you tried getting rid of all the extra whitespace in that line?
– miken32
Nov 7 at 19:03
"doesn't seem to work" doesn't give us a lot to go on. Does the extra header get sent at all with the request? Have you tried getting rid of all the extra whitespace in that line?
– miken32
Nov 7 at 19:03
doesn't seem to work - The page i request is logged out , cookie doesnt seem to work.. whereas if i send curl request with that cookie file , response is logged in
– Gracie williams
Nov 7 at 19:04
doesn't seem to work - The page i request is logged out , cookie doesnt seem to work.. whereas if i send curl request with that cookie file , response is logged in
– Gracie williams
Nov 7 at 19:04
Ok, but again, "logged out" doesn't mean anything in the context of us looking at this code. Have you verified that the cookie header is getting sent with the request?
– miken32
Nov 7 at 19:10
Ok, but again, "logged out" doesn't mean anything in the context of us looking at this code. Have you verified that the cookie header is getting sent with the request?
– miken32
Nov 7 at 19:10
how do i check if its sent ?
– Gracie williams
Nov 7 at 19:11
how do i check if its sent ?
– Gracie williams
Nov 7 at 19:11
Hmm, not sure actually, if you don't have access to the server. Did you try formatting the cookie properly per my answer?
– miken32
Nov 7 at 19:15
Hmm, not sure actually, if you don't have access to the server. Did you try formatting the cookie properly per my answer?
– miken32
Nov 7 at 19:15
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
According to RFC 6265:
Serialize the cookie-list into a cookie-string by processing each
cookie in the cookie-list in order:
Output the cookie's name, the %x3D ("=") character, and the cookie's value.
If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ").
In other words, no spaces around the equal sign, and each cookie should be separated by a semicolon and a space:
$header = [
'Cookie: InterSecure=AyDzUp5AEKz0ErJYeJF2221lIA$$; ASP.NET_SessionId=eqyrgo545czouimlnqc223f0qyi',
];
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
According to RFC 6265:
Serialize the cookie-list into a cookie-string by processing each
cookie in the cookie-list in order:
Output the cookie's name, the %x3D ("=") character, and the cookie's value.
If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ").
In other words, no spaces around the equal sign, and each cookie should be separated by a semicolon and a space:
$header = [
'Cookie: InterSecure=AyDzUp5AEKz0ErJYeJF2221lIA$$; ASP.NET_SessionId=eqyrgo545czouimlnqc223f0qyi',
];
add a comment |
up vote
1
down vote
According to RFC 6265:
Serialize the cookie-list into a cookie-string by processing each
cookie in the cookie-list in order:
Output the cookie's name, the %x3D ("=") character, and the cookie's value.
If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ").
In other words, no spaces around the equal sign, and each cookie should be separated by a semicolon and a space:
$header = [
'Cookie: InterSecure=AyDzUp5AEKz0ErJYeJF2221lIA$$; ASP.NET_SessionId=eqyrgo545czouimlnqc223f0qyi',
];
add a comment |
up vote
1
down vote
up vote
1
down vote
According to RFC 6265:
Serialize the cookie-list into a cookie-string by processing each
cookie in the cookie-list in order:
Output the cookie's name, the %x3D ("=") character, and the cookie's value.
If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ").
In other words, no spaces around the equal sign, and each cookie should be separated by a semicolon and a space:
$header = [
'Cookie: InterSecure=AyDzUp5AEKz0ErJYeJF2221lIA$$; ASP.NET_SessionId=eqyrgo545czouimlnqc223f0qyi',
];
According to RFC 6265:
Serialize the cookie-list into a cookie-string by processing each
cookie in the cookie-list in order:
Output the cookie's name, the %x3D ("=") character, and the cookie's value.
If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ").
In other words, no spaces around the equal sign, and each cookie should be separated by a semicolon and a space:
$header = [
'Cookie: InterSecure=AyDzUp5AEKz0ErJYeJF2221lIA$$; ASP.NET_SessionId=eqyrgo545czouimlnqc223f0qyi',
];
edited Nov 7 at 19:17
answered Nov 7 at 19:07
miken32
22.7k84671
22.7k84671
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195932%2fuse-cookie-saved-by-curl-in-stream-get-contents%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"doesn't seem to work" doesn't give us a lot to go on. Does the extra header get sent at all with the request? Have you tried getting rid of all the extra whitespace in that line?
– miken32
Nov 7 at 19:03
doesn't seem to work - The page i request is logged out , cookie doesnt seem to work.. whereas if i send curl request with that cookie file , response is logged in
– Gracie williams
Nov 7 at 19:04
Ok, but again, "logged out" doesn't mean anything in the context of us looking at this code. Have you verified that the cookie header is getting sent with the request?
– miken32
Nov 7 at 19:10
how do i check if its sent ?
– Gracie williams
Nov 7 at 19:11
Hmm, not sure actually, if you don't have access to the server. Did you try formatting the cookie properly per my answer?
– miken32
Nov 7 at 19:15