简体   繁体   中英

(PHP) Getting Blank Page with Curl (Mytischtennis)

I´m new to php and trying to program a few things.

In the first step I want to show the following page: " https://www.mytischtennis.de/public/home " on my website. I am using Curl to grab the page. But every time I want to output the page I am getting a blank page.

My code looks like this:

<?php

function grab_page($site){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 40);
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_URL, $site);

    ob_start();
    return curl_exec($ch);
    ob_end_clean();
    curl_close($ch);
}

echo grab_page("https://www.mytischtennis.de/public/home");
echo "hallo";
?>    

With other pages this code works. Only for " https://www.mytischtennis.de/public/home " it wont work for me? Can someone help me why i get only with this site a blank page?

Thank you :)

You need to set two more options in your curl request:

// Add some more headers here if you need to
$headers = [
    "Accept-Encoding: gzip, deflate, br"
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Decode the response automatically when needed
curl_setopt($ch, CURLOPT_ENCODING, '');

After this you will get the page you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM