Hi All
I am having trouble with an API for TPP when checking for domain availability, I get the following error in apache2 logs. The script wasn’t written by me and is several years old.
[Mon Jan 23 09:01:27 2012] [error] [client 123.45.67.89] PHP Notice: Undefined offset: 0 in /site/root/availability.php on line 169
[Mon Jan 23 09:01:27 2012] [error] [client 123.45.67.89] PHP Notice: Undefined offset: 1 in /site/root/availability.php on line 169
[Mon Jan 23 09:01:27 2012] [error] [client 123.45.67.89] PHP Notice: Undefined offset: 2 in /site/root/availability.php on line 169
The error refers to this section of the below function:
$t = 0;
while($t < 3) {
ltrim($availabilityString[$t]);
$availabilityString[$t] = substr($availabilityString[$t], 2);
$t++;
}
The function causing the issue:
function outputResults($output) {
$i = 0;
$counter = 0;
$length = intval(strlen($output));
$availabilityString = array();
$available = array();
$notAvailable = array();
$failure = array();
$headingArray = array('Available Domains','Taken Domains','Failed Domain Checks');
while($counter < 3) {
$x = 0;
if($counter == 0) {
while($output[$i] != '<') {
if($output[$i] == ':') {
$x = 1;
// $i = $i + 2;
}
if($x == 1) {
$availabilityString[$counter] = $availabilityString[$counter] . $output[$i];
}
$i++;
}
} else if($counter == 1) {
while($output[$i] != '<') {
if($output[$i] == ':') {
$x = 1;
// $i = $i + 2;
}
if($x == 1) {
$availabilityString[$counter] = $availabilityString[$counter] . $output[$i];
}
$i++;
}
} else {
while($i < $length) {
if($output[$i] == ':') {
$x = 1;
// $i = $i + 2;
}
if($x == 1) {
$availabilityString[$counter] = $availabilityString[$counter] . $output[$i];
}
$i++;
}
}
$i = $i+4;
$counter++;
}
$t = 0;
while($t < 3) {
ltrim($availabilityString[$t]);
$availabilityString[$t] = substr($availabilityString[$t], 2);
$t++;
}
if($availabilityString[0] != '') {
$available = explode('|', $availabilityString[0]);
$countAvailable = count($available);
$t = 0;
print('<h2 class="blue">Available Domains</h2><p>');
while($t < $countAvailable) {
print('www.<strong>' . $available[$t] . "</strong><br />");
$t++;
}
print('</p>');
}
if($availabilityString[1] != '') {
$notAvailable = explode('|', $availabilityString[1]);
$countNotAvailable = count($notAvailable);
$t = 0;
print('<h2 class="red">Taken Domains</h2><p>');
while($t < $countNotAvailable) {
print('www.<strong>' . $notAvailable[$t] . "</strong><br />");
$t++;
}
print('</p>');
}
if($availabilityString[2] != "") {
$failure = explode('|', $availabilityString[2]);
$countFailure = count($failure);
$t = 0;
print('<h2 class="red">Failed Domain Checks</h2><p>');
while($t < $countFailure) {
print('- www.<strong>' . $failure[$t] . "</strong><br />");
$t++;
}
print('</p>');
}
print("<p>Please note: The domain checker does not reserve your chosen domain or guarantee a successful registration.</p>");
if($availabilityString[0] != '') {
print('<h2 class="green">To register your domain, please call one of our consultants</h2>');
}
}
Any help would be appreciated