- substr_count: documentation ( source)
- parse_str: documentation ( source)
- preg_match: documentation ( source)
- print_r: documentation ( source)
- parse_url: documentation ( source)
- http_build_query: documentation ( source)
<?php
$url = 'http://api.tivi8k.net/viettel/?cid=160&token=P6cf0Swsh62FKd773_q_Cg&e=1499794112';
$parse = parse_url($url);
print_r($parse);
function unparse_url($parsed_url) {
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
$pass = ($user || $pass) ? "$pass@" : '';
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
return "$scheme$user$pass$host$port$path$query$fragment";
}
$c = 'go';
if (isset($parse['host']) && preg_match('/.*?\.tivi8k\.net/', $parse['host'])) {
if (isset($parse['path']) && substr_count($parse['path'], '/') === 2) {
$parse['path'] = '/ffff/';
parse_str($parse['query'], $params);
if (isset($params['token']) && isset($params['e'])) {
$a = array(
'id',
'cid',
'channel'
);
foreach ($a as $b) {
if(isset($params[$b])) {
unset($params[$b]);
$params[$c]='ddd';
echo $_GET['bb'];
}
}
$params['token'] = 'hello';
$parse['query'] = http_build_query($params);
}
}
}
print_r(unparse_url($parse));
?>