Saving a curl response into a php variable -
i trying access ec2's public hostname inside instance.
i run command
curl http:// 169 254.169.254/latest/meta-data/public-hostname
inside php script , save response variable. how can this?
you can this
<?php //url of targeted site $url = "http://www.yahoo.com/"; $ch = curl_init(); // set url , other appropriate options curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_returntransfer, true); // grab url , pass browser $output = curl_exec($ch); //echo $output; // close curl resource, , free system resources curl_close($ch); ?>
the $output
variable contains response.
Comments
Post a Comment