function views_append_request_with_cookie in Views PDF 7.3
Same name and namespace in other branches
- 8 modules/views_append/views_append.module \views_append_request_with_cookie()
- 6 modules/views_append/views_append.module \views_append_request_with_cookie()
- 7 modules/views_append/views_append.module \views_append_request_with_cookie()
- 7.2 modules/views_append/views_append.module \views_append_request_with_cookie()
This function emulates the request of a browser. This is used to get the PDF file to append.
1 call to views_append_request_with_cookie()
- views_append_handler_append_view::render in modules/
views_append/ views_append_handler_append_view.inc - This method renders the other view.
File
- modules/
views_append/ views_append.module, line 25 - Module for appending PDF views to other PDF views
Code
function views_append_request_with_cookie($url, $save_path) {
$urlComponents = parse_url($url);
// Define the specified port
if ($urlComponents['scheme'] === 'http') {
$port = 80;
}
elseif ($urlComponents['scheme'] === 'https') {
$port = 443;
}
else {
$port = 80;
}
// Define the host
$host = $urlComponents['host'];
// Define the path
if (!empty($urlComponents['query'])) {
$path = $urlComponents['path'] . '?' . $urlComponents['query'];
}
else {
$path = $urlComponents['path'];
}
// Change host if ssl is used:
if ($port == 443) {
$hostUrl = "ssl://" . $host;
}
else {
$hostUrl = $host;
}
$fp = fsockopen($hostUrl, $port, $errno, $errstr, 30);
$method = 'GET';
$content = '';
if (!$fp) {
echo "{$errstr} ({$errno})<br />\n";
}
else {
$out = "{$method} {$path} HTTP/1.1\r\n";
$out .= "Host: {$host}\r\n";
if ($method == 'POST') {
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
}
$out .= "Content-length: " . strlen($content) . "\r\n";
$out .= "Cookie: " . session_name() . '=' . session_id() . "; \r\n";
$out .= "Connection: Close\r\n\r\n";
if ($method == 'POST') {
$out .= $content;
}
fwrite($fp, $out);
$newFile = fopen($save_path, 'w');
$header = TRUE;
while (!feof($fp)) {
$content = fgets($fp, 8096);
if ($content == "\r\n") {
$header = FALSE;
}
elseif (!$header) {
fwrite($newFile, $content);
}
}
fclose($fp);
fclose($newFile);
}
}