PHP/cURL POST question

CuriousMike

Diamond Member
Feb 22, 2001
3,044
544
136
I've been working on my first real PHP project that tracks Steam games that go on sale.
The basics work fine, and I'm trying to add functionality.

I track a games history of being on sale, and as part of the game data I collect the publisher and developer.

It works well except for when a game is rated M(mature), and Steam has an "Age Check" page in front of the games normal page (where the pub and dev data reside).

I was (still am, really) clueless as to how to solve and asked over on PHPFreaks for help.
(http://www.phpfreaks.com/forums/index.php?topic=351070.0)

I get that I'm needing to POST valid age data to the website; I'm using the "curl" library to do that.

The initial URL looks like this:
http://store.steampowered.com/agecheck/app/1250/#

The page looks to need these fields filled out:
curl_setopt($ch,CURLOPT_POSTFIELDS,'snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=1&ageYear=1990');

Curl returns me a new URL:
http://store.steampowered.com/app/1250
... which should be the direct link to the page, but when echo'ing the new URL contents, I get the age-check front door again.

Anyone have any suggestions, or perhaps attempt to help me define what I'm technically trying to do?
 

Cogman

Lifer
Sep 19, 2000
10,286
147
106
ageMonth should be the name of the month (dumb, I know). so ageMonth=July. Though that won't fix your problem.

Your problem is that steam checks for a cookie and displays content based on the cookie given. In your HTTP request you need to send over cookie information. Mine for steam looks like this

Code:
Steam_Language=english; steamCC_10_0_121_5=US; browserid=5694539310646883797; birthtime=331282801; lastagecheckage=1-July-1980; recentapps=%7B%221250%22%3A1325863982%7D; timezoneOffset=-25200,0
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Cogman's correct, I'm pretty sure curl has a facility to maintain cookies for you. Shouldn't be too difficult to add.
 

CuriousMike

Diamond Member
Feb 22, 2001
3,044
544
136
Cogman - Thank you!
I'm hip to cookies being stored on the client, but oblivious that they would be sent back to the server (?)

I'm sure I have a superfluous option below, but this works.

Code:
<?php
$ckfile = tempnam ("/", "CURLCOOKIE");

$ch = curl_init();
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch,CURLOPT_URL, 'http://store.steampowered.com/agecheck/app/9050/#'); 
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,'snr=1_agecheck_agecheck__age-gate&ageDay=1&ageMonth=May&ageYear=1990');

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_FRESH_CONNECT,true);
curl_setopt ($ch, CURLOPT_UNRESTRICTED_AUTH,true);

curl_setopt ($ch, CURLOPT_COOKIEFILE, $ckfile);
$myPage = curl_exec($ch);
if ($myPage)
{
    echo ('success<br>');
    echo ($myPage);
}
else
    echo ('fail<br>');
?>
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Well what good would a cookie be if you it was write only to the client? The general idea is the server will give the client a piece of encoded data that identifies that client as a unique client. Then on every request the client sends that data back to the server so the server now has a way to look up which session in memory the incoming request belongs to.

Glad you got it working!
 

CuriousMike

Diamond Member
Feb 22, 2001
3,044
544
136
Well what good would a cookie be if you it was write only to the client?

I suppose I wasn't really thinking about it... der.

For my site, I'm using server-side session data which works well, but has caused me some issues that I think a cookie solution might solve.

That'll be round 2.