简体   繁体   中英

php get error to curl url from array get in file

I get Error When Curl Data From URL ( Url From Array get in file ). When I use Normaly URL, It Work Correctly, But When I get URL from Array and run a loop for it, and call function curl to run every line url? it not work, I don't know why. but i need someone help me, I had turn on error report php , but nothing error !

Example File "link.txt"

https://www.fshare.vn/file/4UNG2NRPW5OQ
https://www.fshare.vn/file/CFTJYXKPMN7Q
https://www.fshare.vn/file/RMHD2XBFY93F
https://www.fshare.vn/file/I4TIUE6E9QOV
https://www.fshare.vn/file/5PV15EB38M7T
https://www.fshare.vn/file/ZDLJNDNWCNYM
https://www.fshare.vn/file/O1VYZUXXJNCI
https://www.fshare.vn/file/SD5C1VZ38IPN

And My PHP code

<?php
error_reporting(E_ALL);

$lines = file('link.txt', FILE_IGNORE_NEW_LINES); // Turn Every Line To Array From File , Or use other below Method
//$lines = explode("\n",fopen('link.txt',"r")); // Other Method Get Content To Array
//$lines = explode("\n",file_get_contents('link.txt')); // Other Method Get Content To Array

foreach($lines as $key => $value){
    echo $value . "</br>"; 
    echo get_data($value); // It not Work , Why is that ? 
    echo get_data("https://www.fshare.vn/file/ACKM6ONXFZJE"); // It Work Normally
    die();
}


function get_data($url = null) {
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type' => 'application/x-www-form-urlencoded', 'charset' => 'utf-8'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0");
    curl_setopt($ch, CURLOPT_COOKIESESSION, true);
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com.vn/');
    $data           = curl_exec($ch);


    curl_close($ch);
    return $data;
}

Right now, i have tested again and it work correctly ! Don't know what happened !

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