简体   繁体   中英

404 Not Found PHP

I'm trying to access remote data with Curl or file_get_contents, but they both return 404 Not found. The same link in browser and on different server works. Maybe something is disabled in php config?

Here is the same function with Curl and file get contents:

    public function getNowPlaying() {

    $source = "http://v12.radionsm.lv/lv/stats";//$this->url . "/lv/stats";

    $ch = curl_init($source);
    curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    if (curl_exec($ch) === FALSE) {
        die("Curl error: " . curl_error($ch));
    }
    $data = curl_exec($ch);
    curl_close($ch);
    $xml = simplexml_load_string($data);

    $data = array(
        'status' => (string) $xml->status,
        'onAir' => (string) $xml->dj_name,
        'artist' => (string) $xml->artist_name,
        'title' => (string) $xml->song_name,
        'albumArt' => (string) $this->medium($xml->song_pic)
    );

    return $data;
    }

    public function getNowPlaying() {

        $source = "http://v12.radionsm.lv/lv/stats";
        echo file_get_contents($source);


    }

Thank you.

I think this is some kind of protection from auto scrapping. So you need to repeat browser behaviour to get read that page.

Try to set up CURLOPT_REFERER with valid homepage url. You need to send everyone header in your curl request, which is sent by browser.

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