You are not logged in.

#1 2020-01-25 8:05 am

jasonc310771
Member
Registered: 2020-01-25
Posts: 5

basic API install

I am looking for a simple basic install for a registration page.  I have tried to do this myself but not getting very far.
Here is what I have got to so far.

copied the code from this site.

//    StopForumSpam API Key            **********
function isSpam() {
return;
$fromlink4 = $_SERVER['REMOTE_ADDR'] != "" ? gethostbyaddr($_SERVER['REMOTE_ADDR']) : "" . $_SERVER['REMOTE_ADDR'] . "";

// setup the URL
$url = 'http://api.stopforumspam.org/api';
$data = array(
    'ip' => $fromlink4,
    "confidence"
);

$data = http_build_query($data);

// init the request, set some info, send it and finally close it
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
//return $result;

$xml=simplexml_load_string($result) or die("error");
$res = $xml->appears;

    return $xml; // possible spam
    //return ""; // no spam
}



then I just call the function from my contact and registration page to see if it is likely to be a spammer.

Where do I put my API key ?

Offline

#2 2020-01-25 10:24 am

Maikuolan
Member
From: Perth, Western Australia
Registered: 2011-08-09
Posts: 799
Website

Re: basic API install

You don't need an API key to check the database. You only need an API key to submit to the database. That means, if you want to contribute new data to the database here, you'll need an API key, but if you only want to check the database to see whether an IP address has been reported for spamming, you won't need an API key.

Offline

#3 2020-01-25 12:30 pm

jasonc310771
Member
Registered: 2020-01-25
Posts: 5

Re: basic API install

Ok thanks, Using the code above and also just using

$data = array(
    'ip' => $fromlink4
);

I still get a blank result string.  I am sure my IP is not in the database, but would have thought I get a result to say that it did not 'appear' with 0

Offline

#4 2020-01-25 1:30 pm

Maikuolan
Member
From: Perth, Western Australia
Registered: 2011-08-09
Posts: 799
Website

Re: basic API install

Try removing that first "return;", which you've got right at the beginning of your code. That "return;" would be prematurely ending your function, preventing any of the code that comes after from executing properly.

Offline

#5 2020-01-25 1:35 pm

jasonc310771
Member
Registered: 2020-01-25
Posts: 5

Re: basic API install

opps sorry typo on my part, that was taken out in my live code.

here is what I actually have now...

function isSpam() {
//return;
$fromlink4 = $_SERVER['REMOTE_ADDR'] != "" ? $_SERVER['REMOTE_ADDR'] : "" . $_SERVER['REMOTE_ADDR'] . "";

// setup the URL
$url = 'http://api.stopforumspam.org/api';
$data = array(
    'ip' => $fromlink4
);

$data = http_build_query($data);

// init the request, set some info, send it and finally close it
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
//return $result;

$xml=simplexml_load_string($result) or die("error");
$res = $xml->appears;
return $xml;
        if ($res == "yes") {
            return "yes"; // possible spam
        } else {
            return ""; // no spam
        }
}

Offline

#6 2020-01-25 5:31 pm

jasonc310771
Member
Registered: 2020-01-25
Posts: 5

Re: basic API install

For some reason it worked without any changes to the code i showed above.  I think the xml result it not visible on the screen or in an export from a mysql table i tried to stop it in ?!

Offline

Board footer

Powered by FluxBB

Close
Close