 |
|
Code (PHP)
<?php
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
$url = 'https://www.google.com';
$sources = curl($url);
$cache_active = true;
$cache_time = 7200;
$cache_path = 'cache/test.cac';
if($cache_active && file_exists($cache_path) && (time() - filemtime($cache_path) < $cache_time)) {
$data = @file_get_contents($cache_path);
echo $data;
} else {
$data = @file_get_contents($sources);
$json = json_decode($data,TRUE);
if ($json['title'][0]['title'] != NULL) {
@file_put_contents($cache_path, $data);
}
echo $data;
}
function curl($url)
{
$ch = @curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$head[] = "Connection: keep-alive";
$head[] = "Keep-Alive: 300";
$head[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$head[] = "Accept-Language: en-us,en;q=0.5";
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$page = curl_exec($ch);
curl_close($ch);
return $page;
}
?>
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2018-12-09 14:42:20 |
By :
nengkub |
View :
728 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |