Check IP and Echo Different Variable

General discussions related to php

Moderators: macek, egami, gesf

Post Reply
seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: Check IP and Echo Different Variable

Post by seandisanti » Fri Feb 08, 2013 1:42 pm

just use a ternary operator...

Code: Select all

echo ($variableHoldingVisitorIP==$variableHoldingIPToMatch)?'<a href="../../UntoldRiches/YoureTheLuckyOne/Oops/IforgotToRestrictIndexingForThisDirectoryWithMyRobotsTxtAndAnyoneCanGoogleItImScrewed/secret.php">Top Secret Page for your eyes only</a>':'I know something you don\'t know';
you can break that up into lines too for readability if you're into that.

Code: Select all

echo (Boolean Condition)?
//true Response
: //or
//false response
;

php9
New php-forum User
New php-forum User
Posts: 13
Joined: Fri Feb 22, 2013 2:20 am

Re: Check IP and Echo Different Variable

Post by php9 » Fri Feb 22, 2013 2:31 am

Something like this would do it

Code: Select all

$link1= 'http://link1';
$link2 = 'http://link2';

$link = $ipAddress == '127.0.0.1' ? $link1 : $link2;

echo '<a href="' . $link . '">My link</a>';

Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 2 guests