Commit 8f842ea4 authored by alinetenorio's avatar alinetenorio
Browse files

atualizando validação

parent 02d5a421
...@@ -16,11 +16,6 @@ class GrupoPesquisaValidation ...@@ -16,11 +16,6 @@ class GrupoPesquisaValidation
$url = filter_var($url, FILTER_SANITIZE_URL); $url = filter_var($url, FILTER_SANITIZE_URL);
// // Validate url
// if (!filter_var($url, FILTER_VALIDATE_URL)) {
// return false;
// }
//If url doesn't have a protocol //If url doesn't have a protocol
if(substr($url, 0, 4) != 'http'){ if(substr($url, 0, 4) != 'http'){
$url = 'http://' . $url; $url = 'http://' . $url;
...@@ -30,31 +25,7 @@ class GrupoPesquisaValidation ...@@ -30,31 +25,7 @@ class GrupoPesquisaValidation
return false; return false;
} }
if($this->getHttpResponseCode_using_getheaders($url) != 200){
return false;
}
return true; return true;
} }
function getHttpResponseCode_using_getheaders($url, $followredirects = true)
{
if (!$url || !is_string($url)) {
return false;
}
$headers = @get_headers($url);
if ($headers && is_array($headers)) {
if ($followredirects) {
$headers = array_reverse($headers);
}
foreach ($headers as $hline) {
if (preg_match('/^HTTP\/\S+\s+([1-9][0-9][0-9])\s+.*/', $hline, $matches)) {
$code = $matches[1];
return $code;
}
}
return false;
}
return false;
}
} }
\ No newline at end of file
...@@ -4,6 +4,7 @@ class LattesValidation ...@@ -4,6 +4,7 @@ class LattesValidation
{ {
public function validate($attribute, $value, $parameters, $validator) public function validate($attribute, $value, $parameters, $validator)
{ {
// dd($this->isValidUrl($value));
return $this->isValidUrl($value); return $this->isValidUrl($value);
} }
...@@ -16,12 +17,6 @@ class LattesValidation ...@@ -16,12 +17,6 @@ class LattesValidation
} }
$url = filter_var($url, FILTER_SANITIZE_URL); $url = filter_var($url, FILTER_SANITIZE_URL);
// Validate url
// if (!filter_var($url, FILTER_VALIDATE_URL)) {
// dd('1');
// return false;
// }
//If url doesn't have a protocol //If url doesn't have a protocol
if(substr($url, 0, 4) != 'http'){ if(substr($url, 0, 4) != 'http'){
...@@ -31,33 +26,9 @@ class LattesValidation ...@@ -31,33 +26,9 @@ class LattesValidation
//dd(parse_url($url)['host'] != 'lattes.cnpq.br'); //dd(parse_url($url)['host'] != 'lattes.cnpq.br');
if(parse_url($url)['host'] != 'buscatextual.cnpq.br' && parse_url($url)['host'] != 'lattes.cnpq.br'){ if(parse_url($url)['host'] != 'buscatextual.cnpq.br' && parse_url($url)['host'] != 'lattes.cnpq.br'){
return false; return false;
} }
if($this->getHttpResponseCode_using_getheaders($url) != 200){
return false;
}
return true; return true;
} }
function getHttpResponseCode_using_getheaders($url, $followredirects = true)
{
if (!$url || !is_string($url)) {
return false;
}
$headers = @get_headers($url);
if ($headers && is_array($headers)) {
if ($followredirects) {
$headers = array_reverse($headers);
}
foreach ($headers as $hline) {
if (preg_match('/^HTTP\/\S+\s+([1-9][0-9][0-9])\s+.*/', $hline, $matches)) {
$code = $matches[1];
return $code;
}
}
return false;
}
return false;
}
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment