v2.5.2
Giriş yap

PHP curl yaptığım dosya ekrana çıktı vermesin istiyorum

g4rymckinn0n
416 defa görüntülendi

php de curl ile bir servisten veri alıyorum. aldığım veriyi bu sayfada görmek istemiyorum.

kod şu şekilde:

function curl_request($method, $url, $post_fields = null, $http_header = []) {

    global $cookie_file;
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_POSTFIELDS => $post_fields,
        CURLOPT_HTTPHEADER => $http_header,
        CURLOPT_COOKIEFILE => $cookie_file,
        CURLOPT_COOKIEJAR => $cookie_file
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}
?>

echo ve print_r kullanmadım bunu neden ekrana basıyor?
ve ekrana basmasını nasıl engellerim?

Cevap yaz
Cevaplar (3)
g4rymckinn0n
804 gün önce

hocam dosyada başka bir kod yok ve kodun tamamı şu şekilde;

$cookie_file = dirname(__FILE__) . '/kaynak.cookie';

login('mail', 'pass');

header('Content-Type: application/json');
echo curl_request('GET', 'https://www.demosite.com');

function login($email, $pass) {

    return curl_request(
        'POST',
        'https://www.demosite.com/ajax/',
        'login_user=' . urlencode($email) . '&login_password=' . urlencode($pass) . '&rememberMe=on',
        array(
            'Accept: */*',
            'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
            'X-Requested-With: XMLHttpRequest',
            'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36',
            'Origin: https://www.demosite.com',
            'Referer: https://www.demosite.com/',
            'Accept-Language: tr-TR,tr;q=0.9'
        )
    );
}

function curl_request($method, $url, $post_fields = null, $http_header = []) {

    global $cookie_file;
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => $method,
        CURLOPT_POSTFIELDS => $post_fields,
        CURLOPT_HTTPHEADER => $http_header,
        CURLOPT_COOKIEFILE => $cookie_file,
        CURLOPT_COOKIEJAR => $cookie_file
    ));
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}
qplot
804 gün önce

denedim ekrana bir şey basmıyor sen fonksıyonu kullandıgın kodu yazarmısın

CURLOPT_HTTPHEADER => $http_header, bundan oturu basıyor olabılır

g4rymckinn0n
804 gün önce

arkadaşlar konu güncel yardımcı olabilecek biri var mı?

curl ile bağlantı kodları var. bu dosya ekrana çıktı veriyor. çıktı vermesin, ben istediğim değişkene istediğim veriyi atayıp o şekilde çıktı alayım istiyorum.