Dave3765 Posted February 17, 2009 Share Posted February 17, 2009 <?php $url = 'http://www.google.com'; $opt = 'CURLOPT_NOBODY'; $val = 1; $html = get($url, $opt, $val); echo $html; function get($url, $opt, $val) { $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, $opt, $val); // This is not working $html = curl_exec($curl); curl_close($curl); return $html; } ?> The above example code does show that body of the request - even though I thought I had set CURLOPT_NOBODY. When CURLOPT's or flags are strings it seems to fail. In this case there is no error - just not the desired result. Can anyone tell me where I'm going wrong? Link to comment https://forums.phpfreaks.com/topic/145519-solved-using-string-as-curlopt-setting-painful/ Share on other sites More sharing options...
genericnumber1 Posted February 17, 2009 Share Posted February 17, 2009 You can do curl_setopt($curl, constant($opt), $val); // This is not working CURLOPT_NOBODY is a constant, not a string. Link to comment https://forums.phpfreaks.com/topic/145519-solved-using-string-as-curlopt-setting-painful/#findComment-764001 Share on other sites More sharing options...
Dave3765 Posted February 17, 2009 Author Share Posted February 17, 2009 So simple. Thanks Link to comment https://forums.phpfreaks.com/topic/145519-solved-using-string-as-curlopt-setting-painful/#findComment-764002 Share on other sites More sharing options...
genericnumber1 Posted February 17, 2009 Share Posted February 17, 2009 Yeah, but do note you can just do <?php $opt = CURLOPT_NOBODY; and the code will work fine as you originally posted it (without the constant() function) Link to comment https://forums.phpfreaks.com/topic/145519-solved-using-string-as-curlopt-setting-painful/#findComment-764004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.