0

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.

3
  • Let me get this straight, the problem is why the request is stopping on the 302 HTTP code? Commented Dec 30, 2015 at 10:58
  • You seem to have forgotten to mention what the problem was. Commented Dec 30, 2015 at 11:00
  • 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. Commented Dec 30, 2015 at 11:04

3 Answers 3

1

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

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
Sign up to request clarification or add additional context in comments.

7 Comments

I edited my question. 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.
@user3210615 Have you tried using this code I posted ? I don't know how the addon was built so I can't say exactly how it works, but I'm pretty sure this 302 can be resolved in curl using this code I provided.
I just tried. I printed out the response and the site wants me to log in -> the log in was not successful. (with the addon, yes)
@user3210615 I just tried with my account and I could sucessfully work with curl using the cookie steamLoginSecure, it's slightly different from the other. Also, take note that this method you are using will only work if are already logged in steam in the browser you run this script. Cookies always changes each time you log in
@user3210615 Yes, it worked. Pay attention that its value is different from the other, so you need to get it too
|
1

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");

5 Comments

I edited my question. 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.
With the CURL option that i mentioned on my answer, you will get the 200 response
Yea, but with the addon I get code 200 right away, because i have managed to log in with the cookie, however with curl the log in does not succeed
You're trying to make the login through the cURL headers, right? If ye, is not the CURLOPT_HTTPHEADER option, but the CURLOPT_COOKIE. Look this: php.net/manual/en/function.curl-setopt.php
@VitorLuis It shouldn't make any difference as he is using Cookie header correctly. And if you use CURLOPT_COOKIE you should get rid of Cookie:
0

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"
));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.