this.user Posted March 27, 2010 Share Posted March 27, 2010 Hi guys, I am trying to implement akismet for a generic forum I wrote. My understanding is that all you do is make a post call to their site and it responded with a yes or no as to whether or not it is spam. Here is what I thought should do it, but it is not working, this is all I have in this file called text.php ( i have taken out my api key and replaced it with *****). <? echo 0; $http_request = "POST $path HTTP/1.0\r\n"; $http_request .= "Host: ******.rest.akismet.com \r\n"; $http_request .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"; $http_request .= "Content-Length: " . strlen($request) . "\r\n"; $http_request .= "User-Agent: generic | Akismet/1.11\r\n"; $http_request .= "\r\n"; $http_request .= $request; echo 1; $response = ''; if( false != ( $fs = @fsockopen('******.rest.akismet.com', '80', $errno, $errstr, 10) ) ) { fwrite($fs, $http_request); echo 2; while ( !feof($fs) ) $response .= fgets($fs, 1160); // One TCP-IP packet fclose($fs); echo $response; $response = explode("\r\n\r\n", $response, 2); print_r($response); }else { trigger_error('Error connecting to host: ' . $host . ' Error number: ' . $errno . ' Error message: ' . $errstr, E_USER_ERROR); } echo 3; ?> but when i run the program I get this back HTTP/1.0 501 Not Implemented Content-Type: text/html Content-Length: 28 This method may not be used.Array ( [0] => HTTP/1.0 501 Not Implemented Content-Type: text/html Content-Length: 28 [1] => This method may not be used. ) I do not understand what this means, and therefore I can not fix it. I would really appreciate it if someone can clarify the use of this, also is the $request variable what should contain the "message" i want checked to see if it is spam?" and what is "$path" suppose to be in the header? Quote Link to comment Share on other sites More sharing options...
beta0x64 Posted March 28, 2010 Share Posted March 28, 2010 assuming that you ripped that off of the development page, examine the next function that they show you. function akismet_verify_key( $key ) { global $ksd_api_host, $ksd_api_port; $blog = urlencode( get_option('home') ); $response = ksd_http_post("key=$key&blog=$blog", 'rest.akismet.com', '/1.1/verify-key', $ksd_api_port); if ( 'valid' == $response[1] ) return true; else return false; } The ksd_http_post() function does not really submit anything. You must set the $request and $path depending on what you want to do. Continuing to read the documentation... the path for a comment check is "api-key.rest.akismet.com/1.1/comment-check" or simply 1.1/comment-check. The $request must follow the pattern of a url encoded parameter string.. Is it starting to make sense? The keys and parameters for $request need these values filled out... blog (required) The front page or home URL of the instance making the request. For a blog or wiki this would be the front page. Note: Must be a full URI, including http://. user_ip (required) IP address of the comment submitter. user_agent (required) User agent information. referrer (note spelling) The content of the HTTP_REFERER header should be sent here. permalink The permanent location of the entry the comment was submitted to. comment_type May be blank, comment, trackback, pingback, or a made up value like "registration". comment_author Submitted name with the comment comment_author_email Submitted email address comment_author_url Commenter URL. comment_content The content that was submitted. Other server enviroment variables In PHP there is an array of enviroment variables called $_SERVER which contains information about the web server itself as well as a key/value for every HTTP header sent with the request. This data is highly useful to Akismet as how the submited content interacts with the server can be very telling, so please include as much information as possible. This call returns either "true" or "false" as the body content. True means that the comment is spam and false means that it isn't spam. If you are having trouble triggering you can send "viagra-test-123" as the author and it will trigger a true response, always. Really the documentation is your best friend when developing a complex application like this... http://akismet.com/development/api/ Get back to me! beta0x64 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.