Forum Moderators: coopster
function getIP() {
// Get the users ip address.
// called and updated when they download or log in
unset($GLOBALS["USERIP"]);
$tmpip;
if ($_SERVER['HTTP_CLIENT_IP']) $tmpip = $_SERVER['HTTP_CLIENT_IP'];
else if ($_SERVER['REMOTE_ADDR']) $tmpip = $_SERVER['REMOTE_ADDR'];
else if ($_SERVER['HTTP_X_FORWARDED_FOR']) $tmpip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else $tmpip = "UNKNOWN";
$GLOBALS["USERIP"] = long2ip($tmpip);
}
later on i do this
<? GLOBAL $USERIP;
print($USERIP . "testes")?>Add a comment to "<?= htmlspecialchars($torrow["name"]);?>
$torrow["name"] is irrelevant. (that part works)
the output is basically:
testesAdd a comment to "Snow White part 2"
but i'm trying to get
255.255.255.255testesAdd a comment to "Snow White part 2"
anyone got tips on what i missed?
[edited by: monsto at 11:24 pm (utc) on Oct. 25, 2003]
if( array_key_exists('HTTP_CLIENT_IP', $_SERVER) ) $tmpip = $_SERVER['HTTP_CLIENT_IP'];
etc
etc
etc
Although I am guessing here as I don't have a machine with php to hand to check what happens when you look for a key that doesn't exist.
If it doesn't work then the first thing I'd do to debug this is to replace the '$tmpip = ' parts with a print statement to see which one, if any is getting executed i.e
if ($_SERVER['HTTP_CLIENT_IP']) print('Executing the HTTP_CLIENT_IP clause - ' . $SERVER['HTTP_CLIENT_IP']);
I use, I believe, the same method as vincevincevince. Declare a global variable outside of any functions
global $globalVar;
function UsesGlobalVar() {
global $globalVar; // miscellaneous code.
$globalVar = $whatever + $thingumajig;
// rest of function.
}
(Disclaimer: done purely from memory and I've done all content and no coding for several weeks. I recommend looking up the syntax to check)