Check http request on server side + remove image source in html pages
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
function getPage($sPath, $asVars)
|
||||
require_once 'settings.php';
|
||||
|
||||
function getPage($sPath, $asVars, $sType)
|
||||
{
|
||||
$bSavePage = Settings::DEBUG;
|
||||
if($bSavePage)
|
||||
@@ -11,17 +13,30 @@ function getPage($sPath, $asVars)
|
||||
}
|
||||
if(!$bSavePage || !file_exists($sFileName) || date('dmY', filemtime($sFileName))!=date('dmY'))
|
||||
{
|
||||
$sPath = 'http://www.ugc.fr/'.$sPath.'?'.http_build_query($asVars);
|
||||
$sUrl = 'http://www.ugc.fr/'.$sPath.'?'.http_build_query($asVars);
|
||||
$oCurl = curl_init();
|
||||
curl_setopt($oCurl, CURLOPT_URL, $sPath);
|
||||
curl_setopt($oCurl, CURLOPT_URL, $sUrl);
|
||||
curl_setopt($oCurl, CURLOPT_HEADER, false);
|
||||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($oCurl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
|
||||
$sContent = curl_exec($oCurl);
|
||||
curl_close($oCurl);
|
||||
|
||||
//Detect failed http request
|
||||
if(strpos(str_replace(array("\r", "\n"), '', $sContent), '<title>Service Temporarily Unavailable</title>')) return getPage($sPath, $asVars, $sType);
|
||||
|
||||
if($bSavePage) file_put_contents($sFileName, $sContent);
|
||||
}
|
||||
return $bSavePage?file_get_contents($sFileName):$sContent;
|
||||
else $sContent = file_get_contents($sFileName);
|
||||
|
||||
//Remove scripting & image source (avoid http request)
|
||||
if($sType=='html')
|
||||
{
|
||||
$sContent = preg_replace('/<script(.*)<\/script>/sU', '', $sContent);
|
||||
$sContent = preg_replace('/<img src="(.*)"(.*)\/>/sU', '<img source="$1"$2/>', $sContent);
|
||||
}
|
||||
|
||||
return $sContent;
|
||||
}
|
||||
|
||||
function setPageMime($sType='html')
|
||||
|
||||
Reference in New Issue
Block a user