Check IP and Echo Different Variable

General discussions related to php

Moderators: egami, macek, gesf

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

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

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

Fri Feb 22, 2013 2:31 am

Something like this would do it

Code: Select all

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

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

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

Post Reply