foreach results check
my script let's people's post and short 15 address per time:
$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');
}
function isValidFLR check address hostname, preg_match (if it an url) and if it not in block list.
Problem is, that if user post like this(one address per line):
google.com
google.net
ksajdkljaskldjalsd.com
Script return's that all of the address wrong. If user try post only one, ALL good, valid address script works great.
So, problem with this script or URL validation check may be ?
What's your suggestion ?
EDIT:
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 {
$开发者_StackOverflowm = 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;
}
You should split the input using ‘explode()‘, searching for "\n" then run the check on each of the lines.
精彩评论