PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Dec 10, 2017 7:33 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Thu Nov 30, 2017 6:43 am 
Offline
Forum Newbie

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 21
Hi,

I'm trying to implement a feature in a program but i'm having troubles fetching the JSON url.

The url is
http://api.stopforumspam.org/api?json&e ... l@here.com

And the code received should be something like this (the "var json" in this case is just an example)

Code:
var json = '{"success":1,"email":{"frequency":1,"appears":1,"confidence":0.03}}',
    obj = JSON && JSON.parse(json) || $.parseJSON(json);

document.write('Is a Spammer? '+obj.email.appears+'<br>');
document.write('Last Seen: '+obj.email.lastseen+'');


Also is it possible to change 1 or 0 in obj.email.appears to yes or no?

Thanks


Top
 Profile  
 
PostPosted: Thu Nov 30, 2017 7:20 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6602
Location: WA, USA
Are you familiar with Javascript? Ever used things like if statements?


Top
 Profile  
 
PostPosted: Thu Nov 30, 2017 12:52 pm 
Offline
Forum Newbie

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 21
Yes, i know how IF statement works i just couldn't remember how.

I have 3 alternatives to run the api but only the first one does make an actual valid request but doesn't retrieve any information or may be misconfigured.

Requesting to 127.0.0.1 works but not in this url
Code:
<html>
Is Spammer? <a id='demo'></a><br>
Last seen: <a id='query'></a>
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var myObj = JSON.parse(this.responseText);
        document.getElementById("demo").innerHTML = myObj.email.appears;
        document.getElementById("query").innerHTML = myObj.email.lastseen;
    }
};
xmlhttp.open("GET", "https://api.stopforumspam.org/api?json&email=email@hotmail.com", true);
xmlhttp.send();
</script>
</html>


Requesting to 127.0.0.1 doesn't work nor the alert popup
Code:
// requires jQuery
<script>
var json = (function () {
    $.ajax({
        type: "GET"
        url: https://api.stopforumspam.org/api?json&email=email@hotmail.com,
        dataType: "json",
        success: function (data) {
            json = data;
        }
    });
    return json;
})();
</script>
<script>
alert(json);
</script>


Request to 127.0.0.1 doesn't work but the code has worked in another project
Code:
// requires jQuery
function isspammer(email) {
  var API_Url = "https://api.stopforumspam.org/api?json&email=";
 
  $.get(API_Url + email, function(jsonObj){
      
    if (jsonObj.length > 0) {
       var list = "The list:<br><br>";
     
      jsonObj.forEach(function(element) {
        list += element + "<br>";
      });
     
    document.write(list);
    }
$(document).ready(function(){
   isspammer("email@hotmail.com");   
});
}


Any help will be great, probably i'm just missing something...
Thanks


Top
 Profile  
 
PostPosted: Fri Dec 01, 2017 2:48 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6602
Location: WA, USA
You can't do a JSON request to their site.

Make a PHP script on your site
Syntax: [ Download ] [ Hide ]
<?php

if (isset($_GET["email"])) {
        header("Content-Type: application/json");
        readfile("https://api.stopforumspam.org/api?json&email=" . urlencode($_GET["email"]));
} else {
        http_response_code(400);
}

then call that (with the email) in your AJAX.


Last edited by requinix on Mon Dec 04, 2017 5:43 am, edited 1 time in total.
readfile, not passthru. I wouldn't edit but that was a big mistake.


Top
 Profile  
 
PostPosted: Fri Dec 01, 2017 3:43 pm 
Offline
Forum Newbie

Joined: Thu Aug 10, 2017 4:48 pm
Posts: 21
Thanks


Top
 Profile  
 
PostPosted: Mon Dec 04, 2017 5:15 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4302
Location: Sofia, Bulgaria
Huh, passthru() ? Isn't it supposed to have a local command as a string parameter? I doubt it has a network protocol wrapper.

And I strongly advice people to use cURL for getting remote content, instead of relying on unsafe file open calls.

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
PostPosted: Mon Dec 04, 2017 5:38 am 
Offline
DevNet Master
User avatar

Joined: Wed Jun 27, 2007 9:44 am
Posts: 4302
Location: Sofia, Bulgaria
Also there are several ways to execute crossdomain AJAX calls, and one of them - JSONP is supported by the service provider you use:

Quote:
JSON Padding

We provide ajax/jquery support with JSONP, which allows for a callback function to be specified around a json result. If no callback function is provided then a standard json response will be provided.

http://api.stopforumspam.org/api?email= ... myFunction
myFunction({"success":1,"email":{"lastseen":"2016-08-28 16:08:09","frequency":255,"appears":1,"confidence":99.95}})

This call will return a mime type of text/javascript

Based on a return of "yes", you can choose to deny registration. The lookup is case insensitive, too. Note that you will get an error message if your IP address or email address is improperly formatted.

See the section below for a more reliable method of scoring queries.


https://www.stopforumspam.com/usage

_________________
There are 10 types of people in this world, those who understand binary and those who don't


Top
 Profile  
 
PostPosted: Mon Dec 04, 2017 5:42 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6602
Location: WA, USA
VladSun wrote:
Huh, passthru() ?

Yeah, wrong function. I meant readfile().

VladSun wrote:
Also there are several ways to execute crossdomain AJAX calls, and one of them - JSONP is supported by the service provider you use:

Good call. I had checked for cross-origin headers but didn't think to look for JSONP support.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group