I wrote this for CCLogBot. I figured it would be beneficial and (hopefully) encouraging to display this information for any developers that wanted to incorporate a method to submit data from their software to ASCIIBin.
Post Variables
ASCIIBin follows the MVC architectural design pattern. As such, it uses a front controller so all actions are issued through index.php. This means all of your submissions should be to: ASCIIBin [Code and Text Collaboration for Debugging] - ASCIIBin
Here are the BIN Submission Variables available:
- a -> Action. Defaults to main page if blank. Use add to submit a new bin
- p -> Private. Set to on to make public. Default is off
- l -> Sets the bin to a Link. Set value to on if submitting a link. Link must contain a valid URL and only a URL. No other text. p will be set to off when this vairable is on.
- type -> This flag determines the output/confirmation of submitted text. Valid values are text, xml or html. HTML is default.
- tags -> Tags, seperated by commas
- pasteinfo -> The actual information you wish to paste. This is the textarea name. Cannot be blank
- emailself -> Send a reminder to yourself. you must be logged in for this function to work.
- emaildelay -> If emailself is on, use this variable to set the amount of time to delay before sending the email reminder. The value is in days and must be an INT.
- passOn -> Set this variable to on if you would like to password protect your BIN submission.
- passtext -> The password to set if passOn is enabled
- subscribe -> Set to on to subscribe to BIN comments. You will receive an email for each comment. User must be logged in.
Login Variables:
- a -> Action. Set to "login"
- sublogin -> Secondary process action. Set to 1
- user -> Username
- pass -> Password
- remember -> Set to on if you would like your session to be remembered. This will set a cookie.
cURL Script
First, we do our basic cURL setup. I'll not go into detail about the functions of cURL. You can read about that here: PHP: cURL - Manual
You can see above we set the URL to ASCIIBin [Code and Text Collaboration for Debugging] - ASCIIBin. You must set a cookiejar and cookiefile in order to login. The rest you can read about yourself from the PHP Manual.Code:$curl_connection = curl_init('http://www.asciibin.com/index.php');
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($curl_connection, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
Login
The following will show you how to login using cURL. If you wish to submit BINs anonymously, skip to the next section. To login we will use this query string:
Here is how:Code:user=<username>&pass=<password>&sublogin=1&a=login
This will submit a login request and actually write your session data to the cookie.txt file, set above. It will look like this:Code:/*
* Login
*/
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, "user=<username>&pass=<password>&sublogin=1&a=login");
curl_exec($curl_connection);
Code:www.asciibin.com FALSE / FALSE 0 PHPSESSID 5e4223f348321e6328d58863b9870aa9
Submit BIN
Now it is time to submit/create the BIN. To submit a bin, we need to send variables a and pasteinfo. You can include any of the variables from above as well. In this example I've included a, p, tags, pasteinfo and type. You might want to include type in yours as well in order to parse the response better.
$data is a variable set earlier which contains the submission text.Code:/*
* Submit Text now
*/
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, "a=add&p=on&tags=codecall,tutorial&pasteinfo=This is a Tutorial&type=text");
$result = curl_exec($curl_connection);
pasteinfo can include BBCode. Code blocks should be wrapped with the code tag in this format: [code=language]// code[/code]. ASCIIBin uses GeSHi so it supports all of the languages found here: GeSHi - Generic Syntax Highlighter :: Home (look along the left hand column).
$resultnow contains your data. Since I chose a 'text' return type, it will contain the URL of the newly submitted bin.
NOTE: If any of the text you submit contains an &, it will need to be URL encoded. You can do that in PHP using urlencode().
Closing cURL
You need to close your cURL connection now:
Code:curl_close($curl_connection);
Problems
If you are having problems connecting/submitting to ASCIIBin, you can print out the curl connection results:
This should give you an idea of the problem. If you need any help or assistance, please feel free to ask me.Code:print_r(curl_getinfo($curl_connection));
Full Code
Since this is a promo for ASCIIBin, I've pasted the full code for the submit function on ASCIIBin. You can tear through it however you like.
Full Source - ASCIIBin
If this is the case then $textS cannot contain the character & in there? Probably a few others but maybe there should be an encrypted input - if thats detected it should grab that - unencrypt it and use that instead. Like a public encryption just so that it can get the &'s and other weird symbols you might want.Code:curl_setopt($curl_connection, CURLOPT_POSTFIELDS, "a=add&p=on&tags=codecall irc,log,chat,CCLogBot&pasteinfo={$textS}&type=text");
Either way - good tut - maybe you should post the bot source too?![]()
Blaine: I covered that in the "NOTE" above:
The urlencode function will properly encode &s for post/get submission. It is also part of the function at ASCIIBin.NOTE: If any of the text you submit contains an &, it will need to be URL encoded. You can do that in PHP using urlencode().
Eventually I am going to post the source for the BOT. It is mostly done by another and I'm not happy with all aspects of the code. I'd rather not post anything shameful. lol. I think I will be writing a short tutorial on how to use the PEAR Net_SmartIRC as well. Are you interested?
Sorry, I suppose I should actually read these things - Usually just looking over the source.
Yes, I think I connected to IRC using java once but that little bot man didnt get far. It was before this place had an IRC channel. It was then I realized I need a command for him to sign out lol.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks