当我使用此功能function get_data($url)
时,我的所有内容网站都会消失,我尝试使用function get_web_page( $url )
,但无效...
使用此功能,我希望在另一个网站上看到来自http://swapes.com/version.txt
的内容..
如果function get_data($url)
无效,可以使用什么?
function get_data($url)
{
$ch = curl_init();
$header = array(
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*\/*;q=0.5",
"Accept-Language: en-us,en;q=0.5",
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Cache-Control: max-age=0",
"Connection: keep-alive",
"Keep-Alive: 300",
"Pragma: ");
$timeout = 30;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FORBID_REUSE,1);
curl_setopt($ch,CURLOPT_FRESH_CONNECT,1);
curl_setopt($ch,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
if(!empty($data)){
return $data;
}elseif(function_exists('file_get_contents')){
return file_get_contents($url);
}else{
return '';
}
}
// Get Latest Version
include_once("../version.php");
$l_version = get_data('http://swapes.com/version.txt');
这是来自footer.php的代码php,当我添加" get_data"代码消失了页脚。
<?
include_once("test1.php");
?>
<div class='logged' id="under-content">
<div id="sub-content-box">
</table></div>
<div id="sub-content-box">
<table id="nested" width="100%" cellpadding=0 cellspacing=0>
<thead>
<tr>
<th colspan="3">Ethics</th>
</tr>
</thead>
</table>
<b>It is important to remember that is a community. We are all here for the same reason and we should help eachother.</b></th><br>
<li><U>Don't Aggressively Unfollow/Unlike</U></li>
<li><U>Don't Spam Profiles/Pages</U></li>
<li><U>Don't Create Multiple Accounts</U></li>
<li><U>Don't Use Bots/Macros/Scripts</U></li>
<li><U>Don't Buy or Sell Accounts</U></li>
<b>Anyone found to be breaking any of this will be removed from this site permanently.</b></div>
<div id="sub-content-box">
<a href="javascript:void(0)" class="button" style="width:208px;height:32px;text-align:center;line-height: 11px;" id="tour"></br>Updates</a>
<div style="background: #FFF6BF;color: #514721;border-color: #FFD324;padding: 5px 10px;margin: 0 0 5px;border: 2px solid #DDDDDD;"><h6>16/05/2011 15:00</h6>New update is available for comments plugin! <br/><a href="javascript: void(0)">Update now</a></div>
<a href="javascript:void(0)" class="button" style="width:208px;height:102px;text-align:center;line-height: 21px;" id="tour"></br>
<div style="font-size:11px;margin:3px 15px"><b>Your Version:</b> <?=($config['version'] < $l_version ? '<strong style="color:red">'.$config['version'].'</strong></a>' : '<strong style="color:green">'.$config['version'].'</strong>')?></span></div>
<div style="font-size:11px;margin:2px 15px"><b>Latest Version:</b> <strong style="color:blue"><?=(!empty($l_version) ? $l_version : $config['version'])?></strong></span></div>
</a>
</div>
</div><?php if (ae_detect_ie()) { ?></td></tr></table><?php } ?>
<div id="sub-content">
<a href="">Terms and Conditions</a> <a href="javascript:void(0)" onclick="$('#content').load('_core/after-login.php?what=politcy&rand='+Math.random()); window.location.hash = 'politcy';">Privacy Politcy</a> <a href="javascript:void(0)" onclick="$('#content').load('_core/after-login.php?what=contact&rand='+Math.random()); window.location.hash = 'contact';">Contact Us</a> <a href="">
</a><a href="#" style="float:right">Swapes.com - All rights reserved (c) 2014 </a>
</div>
</body>
</html>
答案 0 :(得分:0)
您需要添加echo
语句来打印您的函数返回的数据。
// Get Latest Version
include_once("../version.php");
echo $l_version = get_data('http://swapes.com/version.txt'); //<--- Add `echo` as shown.
<?php
function get_data($url)
{
$ch = curl_init();
$header = array(
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*\/*;q=0.5",
"Accept-Language: en-us,en;q=0.5",
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Cache-Control: max-age=0",
"Connection: keep-alive",
"Keep-Alive: 300",
"Pragma: ");
$timeout = 30;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FORBID_REUSE,1);
curl_setopt($ch,CURLOPT_FRESH_CONNECT,1);
curl_setopt($ch,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
if(!empty($data)){
return $data;
}elseif(function_exists('file_get_contents')){
return file_get_contents($url);
}else{
return '';
}
}
// Get Latest Version
include_once("../version.php");
echo $l_version = get_data('http://swapes.com/version.txt');