Page 1 of 1
undefined variable
Posted: Mon Aug 16, 2010 2:32 am
by ANYIM
hi,Anyone please help. Am getting this error Undefined variable: ipFound on line 34
here's the code.
$ipFound = true;
}
if ($ipFound) { <------ line 34
reset($valueSplitted);
Thanks for ur help.
Re: undefined variable
Posted: Mon Aug 16, 2010 3:05 am
by dejvos
I think this code is not enough. I can guess only what it should be.
But I see curly bracket above don't you have a definition of variable in some condition?
For example like that:
Code: Select all
<?php
if(!empty($x) && $condition){
$ipFound = True;
}
if($ipFound){
// IP found
}
?>
In this case
$ipFound is not defined when
$x is empty. You need to add
else branch.
Re: undefined variable
Posted: Mon Aug 16, 2010 4:09 am
by ANYIM
hi,
it's some code i found on the net

and whn i tried to run it i got that error:
the whole code below.
$location = `which arp`;
$arpTable = `$location`;
$arpSplitted = split("\n",$arpTable);
$remoteIp = $GLOBALS['REMOTE_ADDR'];
foreach ($arpSplitted as $value) {
$valueSplitted = split(" ",$value);
foreach ($valueSplitted as $spLine) {
if (preg_match("/$remoteIp/",$spLine)) {
$ipFound = true;
}
if ($ipFound) { <--------------------------------------------------------------
error comes on this line
reset($valueSplitted);
foreach ($valueSplitted as $spLine) {
if (preg_match("/[0-9a-f][0-9a-f][:-]".
"[0-9a-f][0-9a-f][:-]".
"[0-9a-f][0-9a-f][:-]".
"[0-9a-f][0-9a-f][:-]".
"[0-9a-f][0-9a-f][:-]".
"[0-9a-f][0-9a-f]/i",$spLine)) {
return $spLine;
}
}
}
$ipFound = false;
}
}
return false;
}
Re: undefined variable
Posted: Mon Aug 16, 2010 8:16 am
by shawngoldw
Try;
Code: Select all
$valueSplitted = split(" ",$value);
foreach ($valueSplitted as $spLine) {
$ipFound = false;
if (preg_match("/$remoteIp/",$spLine)) {
$ipFound = true;
}
If the statement preg_match does not find a match, ipFound never gets defined. Even if it does find a match, I think ipFound is out of scope for the other if statement. This should fix both issues
Re: undefined variable
Posted: Wed Aug 18, 2010 3:34 am
by ANYIM
Thanks Shawn. Error disappeared

but output is a blank page

Re: undefined variable
Posted: Wed Aug 18, 2010 7:53 am
by shawngoldw
No problem.
What do you want to see on the page? There are no echo's or print's.
Shawn