hello everyone i need your help again just a little help please how would you show a button for an ip
this is like admin role but i wanna do it by ip i have find a code that fits my needs
but its not working its a snippet as i read if you can help me fix it or get it working that be great
also Yes i did try this on localhost not working
heres the code
<?php
/*
this Snippet allows you to display content "ONLY" to a visitor from
a specific IP addresses in a page.
Change the $allowed "value" to the IP address you want.
*/
$allowed = 'IP Goes here';
$userip = $_SERVER;
if($userip == $allowed){
echo "This content is only viewed by the IP address you chose...";
}
?>
If you have error reporting turned on and displaying errors the script should show an error something like not being able to compare a string to an array.
If you want to see the errors with your script, temporarily add the debugging lines to the beginning of your script. i.e.
<?php
declare(strict_types=1);
error_reporting(-1);
ini_set('display_errors', 'true');
/*
this Snippet allows you to display content "ONLY" to a visitor from
a specific IP addresses in a page.
Change the $allowed "value" to the IP address you want.
*/
$allowed = 'IP Goes here';
$userip = $_SERVER;
if($userip == $allowed){
echo "This content is only viewed by the IP address you chose...";
}
else {
echo gettype($userip);
echo gettype($allowed);
}
?>
If you do not get any error(s), then it follows that $userip does not loosely equal $allowed
The “gettype” lines should give you a clue.
I think if you read the documentation, you will probably find that this is not the correct one to use, unless I have misunderstood your requirements.
If you’re using the IP address to control who can get into the admin site, don’t forget to have a plan in place for if that IP address ever changes, or becomes unavailable for some reason and you need to get into admin to change or add another allowed IP.
On localhost, it’s not supposed to show your “actual” IP. It uses 127.0.0.1 because it “thinks” that’s your IP. On a live server, this IP changes to the real user’s IP.