How to echo which domain is found in this code?

mphp

New member
Sorry bit of a noob. I have this code that does something for me when it finds a website that is on the list under $allowed_domains
Once the code finds a listed site I just need code to echo which site it found (echo it or save it to a variable)
How can I add the echo of the found website?

Code:
<?php

if (isset($_SERVER['REMOTE_ADDR'])) {
    $ip = $_SERVER['REMOTE_ADDR'];
} else {
    $ip = '';
}

if (isset($_SERVER['REQUEST_URI'])) {
    $uri = $_SERVER['REQUEST_URI'];
} else {
    $uri = '';
}

$allowed_domains = [
    'site1.com',
    'cool.com',
    'exmaple.com',
// Add more domains here as needed
];

// Function to check if uri contains any
function checkUri($uri, $domains) {
    if (empty($uri)) {
        return false;
    }
 
    foreach ($domains as $domain) {
        if (strpos($uri, $domain) !== false) {
            return true;
        }
    }
 
    return false;
}


if (checkUri($uri, $allowed_domains)) {
    // DO SOMETHING HERE IF FOUND
   
//    echo "Need to echo which domain was found";


} else {
   echo "not found";
}



?>
 
Sorry I'm still don't understating how I can tell

if the response is:
Code:
return True;

which one of the 3 website was the answer?

Code:
$allowed_domains = [
'site1.com',
'cool.com',
'exmaple.com'
];
 
let's write the code again:
PHP:
$referer = 
$allowed_domains = [
    'site1.com',
    'site2.com',
    'example.com',
    'bing.com',
    'google.com',
    // Add more domains here as needed
];

// if you want to block not listed referer
$allowed_domain = array_find($referer, $allowed_domains);
if ($allowed_domain === null) {
    die('Referer is not trusted');
}
then if you are using allowed domain then you can check $allowed_domain to know that is the current allowed domain, you can also use $_SERVER['SERVER_NAME']
 
After much googling I was able to find an example and was able to figure it out ツ.

Thank you for the reply, I'm sure it will help someone else in the future
 
Back
Top