问题描述
我知道,已经有一个关于此的主题......请参阅How to pass the steam age check using curl?......但我是一个新用户,无法在现有主题中发表评论,并且标记为解决方案的答案没有不能再工作了。
我自己的代码在过去(大约 2017 年)运行良好,但现在不再运行了。
这是我过去工作的代码:
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,CURLOPT_COOKIEFILE,$ckfile);
//new start
curl_setopt($ch,CURLOPT_COOKIE,'mature_content=1; path=/app/'.$gameid.';');
//new end
curl_setopt($ch,CURLOPT_HEADER,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",2);
return $body;
}
}
这里是来自上面链接的线程的代码示例,过去似乎也有效(但不再有效):
<?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,$url);
curl_setopt($ch,true);
curl_setopt($ch,"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,$postData);
// curl_setopt($ch,CURLOPT_COOKIESESSION,true);
// curl_setopt($ch,$file);
// curl_setopt($ch,$file);
$strCookie = 'mature_content=' . 1 . '; path=/';
curl_setopt( $ch,$strCookie );
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
?>
我目前测试的内容:
您可以以游戏“RUST”为例:https://store.steampowered.com/app/252490/
页面重定向到年龄检查:https://store.steampowered.com/agecheck/app/252490/
我看到 cookie 集现在使用其他名称(JavaScript 中的“wants_mature_content”而不是“mature_content”),但即使将 PHP 更改为使用新名称,它也不起作用。
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=";
}
编辑:我还在 https://store.akamai.steamstatic.com/public/shared/javascript/shared_global.js 中找到了函数 "V_SetCookie" ... 由上面的代码调用:
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;
}
有人可以帮忙吗? :-) 谢谢!
解决方法
好的,开始工作了。
实际上有 3 个 cookie:“wants_mature_content”、“lastagecheckage”和“birthtime”
打开一个带有年龄检查的页面,例如Chrome,单击“查看页面”,然后在 chrome 中查找 3 个 cookie(及其内容)。使用 PHP 的 curl 设置所有 3 个 cookie 并且它正在工作;-)
,这对我有用
<?php
$url = 'https://store.steampowered.com/bundle/5699/Grand_Theft_Auto_V_Premium_Edition/';
$ch = curl_init();
curl_setopt($ch,CURLOPT_ENCODING,'');
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,['Cookie: birthtime=470682001;lastagecheckage=1-0-1985;']);
$html = curl_exec($ch);
curl_close($ch);
var_dump($html);