Example #1
0
function get_file_content($url)
{
    // make url is direct path in server
    if (strpos($url, '//') === false) {
        $url = h_parse_url($_SESSION['url']) . '/' . $url;
    }
    if (substr($url, 0, 4) != 'http') {
        $url = 'http:' . $url;
    }
    $url = str_replace('&', '&', $url);
    //user agent is very necessary, otherwise some websites like google.com wont give zipped content
    $opts = array('http' => array('method' => "GET", 'header' => "Accept-Language: en-US,en;q=0.8rn" . "Accept-Encoding: gzip,deflate,sdchrn" . "Accept-Charset:UTF-8,*;q=0.5rn" . "User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4rn"));
    $context = stream_context_create($opts);
    $content = file_get_contents($url, false, $context);
    //If http response header mentions that content is gzipped, then uncompress it
    foreach ($http_response_header as $c => $h) {
        if (stristr($h, 'content-encoding') and stristr($h, 'gzip')) {
            //Now lets uncompress the compressed data
            $content = gzinflate(substr($content, 10, -8));
        }
    }
    // if can't get the content
    if (trim($content) == false) {
        $content = file_get_contents($url);
    }
    return $content;
}
Example #2
0
                $file_path = 'asset/js/' . $path_info['filename'] . "." . $path_info['extension'];
                $script->src = $file_path;
            }
        }
        // recreate images link
        foreach ($html_file->find('img') as $h_img) {
            $images_src = $h_img->src;
            if (strpos($images_src, 'http') === false) {
                $h_img->src = h_parse_url($_SESSION['url']) . '/' . $images_src;
            }
        }
        // recreate sub link
        foreach ($html_file->find('a') as $link) {
            $link_href = $link->href;
            if (strpos($link_href, '//') === false) {
                $link->href = h_parse_url($_SESSION['url']) . '/' . $link_href;
            }
        }
        // delete temp file and create html file
        unlink($path . '/tmp');
        $html_file->save($path . '/' . $save_file);
        $step++;
        $_SESSION['step'] = $step;
        echo '<script>location.reload();</script>';
        exit;
        break;
    case "5":
        show_step(true);
        session_destroy();
        break;
}