0

i want to make a command that send a message with button like this

open me plz

So i did this

$url = "https://api.telegram.org/" . $token . "/sendMessage?chat_id=" . $message_chat_id . "&text=" . urlencode($message_text) . '&reply_markup={"inline_keyboard":[[{"text":"Visualizza spoiler!","url":"http://google.com/"}]]}';

and it make this url

https://api.telegram.org/censored/sendMessage?chat_id=censored&text=%2Fspoiler+ciao&reply_markup={"inline_keyboard":[[{"text":"Visualizza spoiler!","url":"http://google.com/"}]]}

when i use this url in browser it works but when i use file_get_contents it doesn't

someone can help me?

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
Dekus
  • 13
  • 1
  • 7
  • Did you try with CURL? What version of PHP is that? Did you check if file_get_contents is enabled on server? – wast Oct 14 '17 at 19:30
  • nop, because until now i used file_get_contents; php5.6; yes it is enabled because if i want to send a simple message it works – Dekus Oct 14 '17 at 19:36
  • Can you try with simple curl? https://stackoverflow.com/questions/7794604/file-get-contents-not-working – wast Oct 14 '17 at 19:42
  • Now it works, i love you man, do u know why with file_get_contents didn't it work? – Dekus Oct 14 '17 at 19:55
  • I don't really know to be honest but I had the same problem with another host some days ago. CURL then worked. I'll add an answer. – wast Oct 14 '17 at 20:19

1 Answers1

1

I had the same problem few days ago and I just tried CURL instead and it worked.

function curl_get_contents($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
wast
  • 878
  • 9
  • 27