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.
undefined variable
Moderator: General Moderators
Re: undefined variable
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:
In this case $ipFound is not defined when $x is empty. You need to add else branch.
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
}
?>Re: undefined variable
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;
}
it's some code i found on the net
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;
}
-
shawngoldw
- Forum Contributor
- Posts: 212
- Joined: Mon Apr 05, 2010 3:38 pm
Re: undefined variable
Try;
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
Code: Select all
$valueSplitted = split(" ",$value);
foreach ($valueSplitted as $spLine) {
$ipFound = false;
if (preg_match("/$remoteIp/",$spLine)) {
$ipFound = true;
}
Re: undefined variable
Thanks Shawn. Error disappeared
but output is a blank page 
-
shawngoldw
- Forum Contributor
- Posts: 212
- Joined: Mon Apr 05, 2010 3:38 pm
Re: undefined variable
No problem.
What do you want to see on the page? There are no echo's or print's.
Shawn
What do you want to see on the page? There are no echo's or print's.
Shawn