I have the following code
<?php
$token = '';
if(!empty($_POST['token'])) $token = $_POST['token'];
$url = '';
if(!empty($_REQUEST['url'])) $url = Sanitize($_REQUEST['url']);
if(!filter_var($url, FILTER_VALIDATE_URL)) return 'erro1';
?>
This page is supposed to be executed by AJAX so I'm coding error codes, now if the URL is not valid, I expect it to return erro1
The problem is, it never returns erro1
. I tried dumping the result of the filter_var and it was false
as expected! The page simply executes and return nothing even though the URL is not valid, but if I switch return with an echo, it works.
Why is that? Why is echo working but not return?