Search code examples
phpcurlcookiesphp-curlsteam

Bypass age check on Steam website (with PHP curl)


I know, there is already a thread about this ... see How to pass the steam age check using curl? ... but I'm a new user and can't comment in an existing thread and the answer marked as solution there doesn't work anymore.

I had my own code that worked fine in the past (around 2017), but doesn't work anymore as well.

Here is my code that worked in the past:

function curl_redirect_exec2($ch, &$redirects, $curlopt_header = false) {
    $ckfile = tempnam(sys_get_temp_dir(), "CURLCOOKIE");
    curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
    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_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'snr=1_agecheck _agecheck__age-gate&ageDay=1&ageMonth=May&ageYear=1990');
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, true);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
    //new start
    curl_setopt($ch, CURLOPT_COOKIE, 'mature_content=1; path=/app/'.$gameid.';');
    //new end
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if($http_code == 301 || $http_code == 302) {
        list($header) = explode("\r\n\r\n", $data, 2);
        $matches = array();
        preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
        $url = trim(array_pop($matches));
        $url_parsed = parse_url($url);
        if(isset($url_parsed)) {
            curl_setopt($ch, CURLOPT_URL, $url);
            $redirects++;
            return curl_redirect_exec2($ch, $redirects);
        }
    }
    if($curlopt_header) {
        return $data;
    } else {
        list(,$body) = explode("\r\n\r\n", $data, 2);
        return $body;
    }
}

And here is the code sample from the thread linked above that also seemed to work in the past (but doesn't anymore):

<?php
$url = "http://store.steampowered.com/app/312660/";
// $file = __DIR__ . DIRECTORY_SEPARATOR . "cookie.txt";
// $postData = array(
// 'ageDay' => '31',
// 'ageMonth' => 'July',
// 'ageYear' => '1993'
// );
$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13");
curl_setopt($ch,CURLOPT_POSTFIELDS,$postData);
// curl_setopt($ch,CURLOPT_COOKIESESSION, true);
// curl_setopt($ch,CURLOPT_COOKIEJAR,$file); 
// curl_setopt($ch,CURLOPT_COOKIEFILE,$file);
$strCookie = 'mature_content=' . 1 . '; path=/';
curl_setopt( $ch, CURLOPT_COOKIE, $strCookie );

curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);

curl_close($ch);
echo $data;
?>

What I tested so far:

You can use the game "RUST" as an example: https://store.steampowered.com/app/252490/

Page redirects to age check: https://store.steampowered.com/agecheck/app/252490/

I saw that the cookie set uses other names now ("wants_mature_content" instead of "mature_content" in the JavaScript), but even after changing the PHP to use the new name, it doesn't work.

JavaScript code from Steam page:

function HideAgeGate( )
{
  var bHideAll = false;
  console.log(bHideAll);
  var strCookiePath = bHideAll ? '/' : "\/app\/252490";
  V_SetCookie( 'wants_mature_content', 1, 365, strCookiePath );

  document.location = "https:\/\/store.steampowered.com\/app\/252490\/Rust\/?snr=";
}

Edit: I also found the function "V_SetCookie" ... in https://store.akamai.steamstatic.com/public/shared/javascript/shared_global.js ... that is called by the code above:

function V_SetCookie( strCookieName, strValue, expiryInDays, path )
{
    if ( !path )
        path = '/';

    var strDate = '';

    if( typeof expiryInDays != 'undefined' && expiryInDays )
    {
        var dateExpires = new Date();
        dateExpires.setTime( dateExpires.getTime() + 1000 * 60 * 60 * 24 * expiryInDays );
        strDate = '; expires=' + dateExpires.toGMTString();
    }

    document.cookie = strCookieName + '=' + strValue + strDate + ';path=' + path;
}

Can somebody help please? :-) Thanks!


Solution

  • Ok, got it working.

    There are actually 3 cookies: "wants_mature_content", "lastagecheckage" and "birthtime"

    Open a page with age check in e.g. Chrome, click on "View Page" and then look for the 3 cookies in chrome (and their content). Set all 3 cookies with PHP's curl and it's working ;-)