Skip to content

Commit 7022a59

Browse files
committed
fixed error when no connect to server
1 parent 34d8861 commit 7022a59

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cleantalk.class.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,8 @@ private function sendRequest($data = null, $url, $server_timeout = 3) {
665665
$result = @file_get_contents($url, false, $context);
666666
}
667667
}
668-
669-
if (!$result) {
668+
669+
if (!$result || !cleantalk_is_JSON($result)) {
670670
$response = null;
671671
$response['errno'] = 1;
672672
if ($curl_error) {
@@ -1166,17 +1166,24 @@ function cleantalk_get_real_ip()
11661166
{
11671167
$headers = $_SERVER;
11681168
}
1169-
if ( array_key_exists( 'X-Forwarded-For', $headers ) && filter_var( $headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) )
1169+
if ( array_key_exists( 'X-Forwarded-For', $headers ) )
11701170
{
1171-
$the_ip = $headers['X-Forwarded-For'];
1171+
$the_ip=explode(",", trim($headers['X-Forwarded-For']));
1172+
$the_ip = trim($the_ip[0]);
11721173
}
1173-
elseif ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) && filter_var( $headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ))
1174+
elseif ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ))
11741175
{
1175-
$the_ip = $headers['HTTP_X_FORWARDED_FOR'];
1176+
$the_ip=explode(",", trim($headers['HTTP_X_FORWARDED_FOR']));
1177+
$the_ip = trim($the_ip[0]);
11761178
}
11771179
else
11781180
{
11791181
$the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
11801182
}
11811183
return $the_ip;
11821184
}
1185+
1186+
function cleantalk_is_JSON($string)
1187+
{
1188+
return ((is_string($string) && (is_object(json_decode($string)) || is_array(json_decode($string))))) ? true : false;
1189+
}

0 commit comments

Comments
 (0)