Check http request on server side + remove image source in html pages

This commit is contained in:
2015-08-29 16:18:22 +02:00
parent 3e69ae7199
commit 304c31d870
3 changed files with 21 additions and 7 deletions

View File

@@ -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')