user3210615
user3210615

Reputation: 17

PHP curl headers(?) issue

There is an addon for firefox called httprequester. (https://addons.mozilla.org/en-US/firefox/addon/httprequester/)

When I use the addon to send a GET request with a specific cookie, everything works fine.

Request header:

GET https://store.steampowered.com/account/
Cookie: steamLogin=*removed because of obvious reasons*

Response header:

200 OK
Server:  Apache
... (continued, not important)

And then I am trying to do the same thing with cURL:

$ch = curl_init("https://store.steampowered.com/account/");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: steamLogin=*removed because of obvious reasons*"));
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
$response = curl_exec($ch);
$request_header = curl_getinfo($ch, CURLINFO_HEADER_OUT);

echo "<pre>$request_header</pre>";
echo "<pre>$response</pre>";

Request header:

GET /account/ HTTP/1.1
Host: store.steampowered.com
Accept: */*
Cookie: steamLogin=*removed because of obvious reasons*

Response header:

HTTP/1.1 302 Moved Temporarily
Server: Apache
... (continued, not important)

I don't know if it has anything to do with my problem, but a thing I noticed is that the first lines of the request headers are different

GET https://store.steampowered.com/account/

and

GET /account/ HTTP/1.1
Host: store.steampowered.com

My problem is that I get 200 http code with the addon and 302 with curl, however I'm sending (or trying to send) the same request.

Upvotes: 0

Views: 241

Answers (3)

Vitor Villar
Vitor Villar

Reputation: 1925

If i really understand your problem, the thing is cURL is not following the redirect. He don't do that by default, you need to set a option:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

With this, cURL is able to follow the redirects.

To set the Cookies to the request use, (You may need pass the user agent):

curl_setopt($ch, CURLOPT_COOKIE, "Cookie: steamLogin=*removed because of obvious reasons*; User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0");

Upvotes: 1

Sabuj Hassan
Sabuj Hassan

Reputation: 39443

I think your addon sends the useragent string by default from the browser. If you add useragent string with your curl request, I believe your problem will resolve!

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Cookie: steamLogin=*removed because of obvious reasons*",
    "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"
));

Upvotes: 0

hlscalon
hlscalon

Reputation: 7552

The page is doing some redirect, so you must follow it

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

Upvotes: 1

Related Questions