You can't do it completely. You could somewhat block direct access by attempting to navigate from their IP addresses origin but that won't always be accurate. A user also may access via a proxy or by being directed from some other source. Your PHP code also will always be hidden from all users regardless of where they are. I assume you are referring to the generated source.
PHP Code:
<?php
if ($user_location == "China") {
$location = "china";
} else {
$location = "unknown";
}
echo "You've location is $location";
//You can assign other variables if the output will be the same at the end or output the full code in each condition and use an exit or die to stop the execution.
?>
Corrections to my coding/thoughts welcome.
Bookmarks