[php] curl GET example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/php
<?php
$url = "http://liho.tw/";
$qry_str = "?x=10&y=20";
// or
$qry_str = "";
$ch = curl_init();
 
// Set query data here with the URL
curl_setopt($ch, CURLOPT_URL, $url . $qry_str);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
$output = trim(curl_exec($ch));
curl_close($ch);
?>