SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Undefined Offset help

  1. #1
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined Offset help

    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:

    PHP Code:
        $t 0;
        while(
    $t 3) {
            
    ltrim($availabilityString[$t]);
            
    $availabilityString[$t] = substr($availabilityString[$t], 2);
            
    $t++;
        } 
    The function causing the issue:

    PHP Code:
    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

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,109
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    isset()
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Member
    Join Date
    Nov 2007
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, while it may be obvious to you, it does not really help me that much. What do I need to do with isset() in order for the script to work? It seems something is deprecated in the above code because it works on an older version of PHP.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,109
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    The index $t is not available in $availabilityString, the index is therefore undefined. As this "used to work", chances are the error reporting has been increased. You can check if the $availabilityString[$t] index "is set" with isset().
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •