extern.php,Dreamhost,curl
我的论坛是用的punbb导入数据以后,发现在其它页面要显示最新帖子的代码不行了,
错误如下:
Warning: include() [function.include]: URL file-access is disabled in the server configuration in /home/.freight/topcool/blog.manboo.info/wp-content/themes/manboo/sidebar.php on line 351
原来下面这句话已经不能用了:
- <?php
- include('http://forums.manboo.info/extern.php?action=active');
- ?>
原因是Dreamhost将allow_url_fopen设为off了。
到punbb和google搜索了下,解决方法是使用$curl用下面的代码,注意根据情况修改红色那句。
- <?php
- $curl_handle = curl_init();
- // Where should we get the data?
- curl_setopt ($curl_handle, CURLOPT_URL, 'http://forums.manboo.info/extern.php?action=active');
- // This says not to dump it directly to the output stream, but instead
- // have it return as a string.
- curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
- // the following is optional, but you should consider setting it
- // anyway. It prevents your page from hanging if the remote site is
- // down.
- curl_setopt ($curl_handle, CURLOPT_CONNECTTIMEOUT, 1);
- // Now, YOU make the call.
- $buffer = curl_exec($curl_handle);
- // And tell it to shut down (when your done. You can always make more
- // calls if you want.)
- curl_close($curl_handle);
- // This is where i’d probably do some extra checks on what i just got.
- // Paranoia pays dividends.
- print $buffer;
- ?>
来源:http://blog.unitedheroes.net/archives/p/1630/
我恼火的是开始改了上面那个代码,并没有显示出来,我以为代码不对,就又去找其它方法。浪费了好多时间,其实是要在论坛里新发一个帖子,激活下才可以显示。
Popularity: 42% [?]
Tags: curl, dreamhost, WordpressRelated posts


