array( 'header' => array( "Content-type: application/json", "X-API-KEY: ". self::X_API_KEY), 'method' => 'GET' ) ); $context = stream_context_create($options); try { $content = @file_get_contents($url, false, $context); if ($content !== false) { return $content; } } catch (Exception $e) {} return ""; } // checkIP checks if ip address is outside age controlled area static function checkIP($ip) { $url = self::GEO . "/geoip/$ip"; $content = self::runGetRequest($url); // in case of error treat users as GB users (require age check) if ($content === "") { return false; } $region = json_decode($content); if ($region->{'region'} === "GB") { return false; } return true; } // getChallenge retrieves challenge signed by content provider static function getChallenge() { $url = self::VERIFIER . '/challenge'; return self::runGetRequest($url); } static function getCustomLoginParameter() { if (self::CUSTOM_LOGIN_PAGE === '') { return ''; } return '&cpBgUrl=' . urlencode(self::CUSTOM_LOGIN_PAGE); } // getRedirectUrl generates redurect url with challenge public static function getRedirectUrl($url) { $challenge = self::SKIP_CHALLENGE_GENERATION ? "" : self::getChallenge(); if ($challenge === "") { return self::AGE_WALL . "?url=" . urlencode($url) . self::getCustomLoginParameter(); } $opts = json_decode($challenge); return self::AGE_WALL . "?message=" . urlencode($opts->{'message'}) . "&url=" . urlencode($url) . self::getCustomLoginParameter(); } // isUserAuthenticated checks if user has valid token in query parameters public static function isUserAuthenticated($params, $ip, $origin) { if (!is_array($params) || $params['uuid'] == "") { if ($ip === 'UNKNOWN') { return false; } if (self::IP_CHECK_ENABLED) { return self::checkIP($ip); } return false; } $js_string = json_encode(array('message' => $params['uuid'])); // use key 'http' even if you send the request to https://... $options = array( 'http' => array( 'header' => array( "Content-type: application/json", "X-API-KEY: ". self::X_API_KEY, "ORIGIN: ". $origin), 'method' => 'POST', 'content' => $js_string ) ); $url = self::VERIFIER . '/verify'; $context = stream_context_create($options); try { $content = @file_get_contents($url, false, $context); if ($content !== false) { return true; } } catch (Exception $e) {} return false; } } ?>