3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Modified the cURL function to accept POST parameters and a cookiejar file // You will actually need to use a cookie jar because the cookie is not static // Using a cookie jar allows the server to change the cookie as needed and the changed cookie is sent back to the server. function request($url, $params=array(), $cookiejar="") { $ch = curl_init(); $curlOpts = array( CURLOPT_URL => $url, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true ); if (!empty($params)) { // If POST values are given, send that shit too $curlOpts[CURLOPT_POST] = true; $curlOpts[CURLOPT_POSTFIELDS] = $params; } if (!empty($cookiejar)) { if(!file_exists($cookiejar)){ echo 'Cookie file missing. please create it first.'; exit; }else if(!is_writable($cookiejar)){ echo 'Cookie file not writable. chmod it to 777.'; exit; } curl_setopt($ch, CURLOPT_COOKIEJAR, realpath($cookiejar)); curl_setopt($ch, CURLOPT_COOKIEFILE, realpath($cookiejar)); } curl_setopt_array($ch, $curlOpts); $answer = curl_exec($ch); // If there was an error, show it if (curl_error($ch)) die(curl_error($ch)); curl_close($ch); return $answer; } // The url you're trying to access $url = "http://store.steampowered.com/app/223470"; // The url that gives us the cookie $cookie_url = "http://store.steampowered.com/agecheck/app/223470/"; // The POST parameters that are sent to the server when requesting a cookie $params = array("ageDay"=>1, "ageMonth"=>"January", "ageYear"=>"1915", "snr"=>"1_agecheck_agecheck__age-gate"); // This request just give us a cookie. request($cookie_url, $params, "cookiejar"); // And this request is that page you need $html = request($url, array(), "cookiejar"); // Domdoc stuff that we already discussed $dom = new domDocument; libxml_use_internal_errors(true); $dom->loadHTML($html); $classname="game_description_snippet"; $finder = new DomXPath($dom); $spaner = $finder->query("//*[contains(@class, '$classname')]"); foreach ($spaner as $spane) { $mo = $spane->nodeValue; echo $mo; }

preferences:
49.41 ms | 402 KiB | 5 Q