Problem: We want to display certain content in a certain case (ex. certain ip to display page)
So we start off with an if statement:
<?php
if($_SERVER['REMOTE_ADDR'] == "127.0.0.1") { //this part annouces that if the ip is 127.0.0.1 to run the code below.
echo "You are 127.0.0.1"; // just an echo which displays content.
} // end the if
Now you can see that is a starting part of an if else statement. But, what if we want to add onto that code and make it display something else for another certain ip. Lets start it off!
<?php
if($_SERVER['REMOTE_ADDR'] == "127.0.0.1") { //this part annouces that if the ip is 127.0.0.1 to run the code below.
echo "You are 127.0.0.1"; // just an echo which displays content.
} // ends the if.
elseif($_SERVER['REMOTE_ADDR'] == "196.168.0.1") { // pratically the same thing as above but we change if to elseif.
echo "You are 196.168.0.1";
}//end that section.
Now when using an if and elseif statement in one code, you will need to always added an else. An else is practically when non of the if or elseif statements fit the criteria they ask.
Lets finish this off.
<?php
if($_SERVER['REMOTE_ADDR'] == "127.0.0.1") { //this part annouces that if the ip is 127.0.0.1 to run the code below.
echo "You are 127.0.0.1"; // just an echo which displays content.
} // ends the if.
elseif($_SERVER['REMOTE_ADDR'] == "196.168.0.1") { // pratically the same thing as above but we change if to elseif.
echo "You are 196.168.0.1";
}//end that section.
else { //start the else.
echo "Your IP is not 127.0.0.1 or 196.168.0.1";
} // end that section
?>
Simple eh? Hopefully, that helped you in your life. If you still don't understand reply to this thread. Some people will be happy to help you.












