SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Php Arrays & Another Question.

    Hey Guys,

    I'm been going crazy trying to figure this out.

    First let me show you half the script

    PHP Code:
    <?php

    // Retrieves the IP of the client
    function getip () {
    $ip="64.201.124.0";
        return 
    $ip;
    }

    // Queries multiple block lists
    function dnsblquery ($ip) {
        
    $dnsbllist[] = array("bl.spamcannibal.org","sbl-xbl.spamhaus.org","bl.spamcannibal.org","sbl-xbl.spamhaus.org");
        if (
    $ip) {
            
    // Reverses the IP
            
    $ips explode("."$ip);
            
    $ipreverse "$ips[3].$ips[2].$ips[1].$ips[0]";
            
    // Queries the block lists listed in dnsbllist
            
    for ($i=0;$i<count($dnsbllist);$i++) {
                if (
    checkdnsrr("$ipreverse.$dnsbllist[$i]""A")) {
                    
    // Returns the blacklist the queried IP is on
                    
    return $dnsbllist[$i];
                }
            }
        }
        return 
    FALSE;

    }
    $blocker dnsblquery(getip());
    Now What I can't figure out is how to list each array that is should be displayed. The script is assumiing that only 1 array matches, so it assigns the 1 array to $bocker.

    But what if there are 3 arrays that match? How can I display 1, 2, 3,4 etc for as many arrays that match?

    I'm not good with arrays, forgive me!

    Any help is appreciated!!

    Thanks!!

  2. #2
    SitePoint Member
    Join Date
    Jan 2005
    Location
    chennai
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,
    This may help you try..
    if you want to assign blocked ip adresses as array use $blocked[] (array) instaed of $blocked(string)
    what you did wrong is while assigning values to array ($dnsbllist) you put $dnsbllist[]. it will assign the whole array for index 0. now i removed the [].

    The code is given below
    -----------------------------------------


    <?php

    // Retrieves the IP of the client
    function getip () {
    $ip="64.201.124.0";
    return $ip;
    }

    // Queries multiple block lists
    function dnsblquery ($ip) {
    $dnsbllist = array("sbl-xbl.spamhaus.org","bl.spamcannibal.org","sbl-xbl.spamhaus.org", "bl.spamcannibal.org");
    if ($ip) {
    // Reverses the IP
    $ips = explode(".", $ip);
    $ipreverse = "$ips[3].$ips[2].$ips[1].$ips[0]";
    // Queries the block lists listed in dnsbllist
    for ($i=0;$i<count($dnsbllist);$i++) {
    if (checkdnsrr("$ipreverse.$dnsbllist[$i]", "A")) {
    // Returns the blacklist the queried IP is on
    $blocked .= $dnsbllist[$i];
    }
    }
    }

    if($blocked)
    {
    return $blocked;
    }
    else
    {
    return false;
    }

    }
    $blocker = dnsblquery(getip());


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
  •