-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinternal-request.php
More file actions
38 lines (36 loc) · 866 Bytes
/
internal-request.php
File metadata and controls
38 lines (36 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/*
* Internal Request: Provides a sub request without opening http connections to the server
* Jonas Raoni Soares da Silva <http://raoni.org>
* https://github.com/jonasraoni/php-internal-request
*/
function internalRequest($path){
static $stack;
$stack[] = '';
$i = count($stack) - 1;
if(strlen($s = ob_get_contents())){
$i ? $stack[$i - 1] .= $s : @ob_flush();
ob_end_clean();
}
$get = null;
$pt = '';
if(($qp = strpos($path, '?')) !== false){
$get = $_GET;
$pt = substr($path, 0, $qp);
foreach(explode('&', substr($path, $qp + 1)) as $qv){
$tv = explode('=', $qv);
$_GET[$tv[0]] = count($tv) > 1 ? $tv[1] : '';
}
}
else
$pt = $path;
ob_start();
include $pt;
$s = ob_get_contents();
ob_end_clean();
if(count($stack) > 1)
ob_start();
$get !== null && ($_GET = &$get);
unset($get);
return array_pop($stack) . $s;
}