我的脚本让我们的人的职位和短期15个地址每次:的foreach结果检查
$err_msg = isValidFLR($flr_post, $ip);
if (!$err_msg) {
list($randlink, $lastid, $scr) = addLink($flr_post, $ip);
$flr_post = check_input($flr_post);
$url_array[$i]['number'] = $i + 1;
$url_array[$i]['flr'] = $flr_post;
$url_array[$i]['flr_substr'] = (strlen($flr_post) > 33) ? substr($flr_post, 0, 33) . '...' : $flr_post;
$url_array[$i]['randlink'] = $randlink;
$url_array[$i]['fullrand'] = $config['indexurl'] . $config['mod_rewrite_char'] . $randlink;
$url_array[$i]['scr'] = $scr;
$url_array[$i]['id'] = $lastid;
$url_array[$i]['flr_length'] = strlen($flr_post);
$url_array[$i++]['randlink_length'] = strlen($config['indexurl'] . $config['mod_rewrite_char'] . $randlink);
} else {
die('Error, omg');
}
功能isValidFLR检查地址的主机名,的preg_match(如果它的URL),如果它不是在阻止列表。
问题是,如果用户后像这样(每行一个地址):
google.com
google.net
ksajdkljaskldjalsd.com
脚本返回的所有地址错误的。如果用户只发布一个,所有有效的地址脚本都很好。
那么,这个脚本或URL验证检查的问题可能是?
您的建议是什么?
编辑:
function isValidFLR(&$flr_post,&$ip) {
preg_match_all("!://!",$flr_post,$matches);
$match_count = count($matches[0]);
if ($match_count>=2) {
$flr_post = preg_replace("!(.+)://((.+)://(.+))!",'\2',$flr_post);
}
elseif ($match_count==0) $flr_post = 'http://'.$flr_post;
if (!preg_match('!^(http|https|ftp)://[\w-]+\.[\w-]+(\S+)?$!i', $flr_post)) {
//if (!preg_match('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i', $flr)) {
return 'wromg address: '.$flr_post;
}
else {
$m = parse_url($flr_post);
$hostname = strtolower($m['host']);
}
// is such host..
if (preg_match('/^\d+\.\d+\.\d+\.\d+/', $hostname)) {
$ip = $hostname;
} else {
$ip = gethostbyname($hostname);
if ($ip===$hostname)
return 'host not found: '.$flr_post;
}
// does host not blocked..
if (in_array($ip,getIPs_array())) {
return 'host blocked: '.$flr_post;
}
return false;
}
如果不包含函数isValidFLR的脚本,该如何判断? – ajreal
好吧,我会更新帖子 – ZeroSuf3r
另外,格式化你的代码很好,白色空间不好。代码片段应该是整洁和相关的。 – ajreal