Im checking users on my website if they use vpn or not with php connected via API, my script working good, if user used vpn an status says : "is a VPN"
if user not using vpn than status says : "is not a VPN"
what i wanted in my script, is that if user do not using vpn whole page of HTML should displayed not a status say : "is not a VPN" and than if using vpn the status says : "is a VPN" normally
<?php
header('Content-type: text/plain');
$IP_ADDRESS = '127.0.0.1'; # Manual IP Address
$API_KEY = "";
$API_URL = 'https://vpnapi.io/api/' . $IP_ADDRESS . '?key=' . $API_KEY;
$response = file_get_contents($API_URL);
$response = json_decode($response);
if(!$response->security->vpn) {
echo " is a VPN.n";
} else {
echo " is not a VPN.n";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
<div style="text-align: center; color: rgb(51, 204, 0);"><big
style="font-weight: bold;"><big><big><br>
Test Working!!!</big></big></big></div>
</body>
</html>
2
Answers
Just as your code already does… Wrap what you want to happen in the
if
andelse
blocks so that it’s simply within those blocks:Alternatively, as a matter of preference and readability, you can remove the
else
entirely and just conditionally return to end the script. For example:Unless I’m misunderstanding and you want the
if
condition to show the message and the page, while the else only shows the page? If that’s the case then what you have is simply a basicif
condition to conditionally perform an operation:Any way you look at it, the structure is always the same. Operations that are conditionally performed (that is, only sometimes performed depending on some data) go in
if
orelse
blocks.A fairly simple change
Alternatively you could output the message as part of the page