+ Reply to Thread
Results 1 to 4 of 4

Thread: Login and Submit Text to ASCIIBin (sample PHP and cURL script)

  1. #1
    Jordan Guest

    Login and Submit Text to ASCIIBin (sample PHP and cURL script)

    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

    Code:
    $curl_connection curl_init('http://www.asciibin.com/index.php');
            
    curl_setopt($curl_connectionCURLOPT_COOKIEJAR"cookie.txt");
            
    curl_setopt($curl_connectionCURLOPT_COOKIEFILE"cookie.txt");
            
    curl_setopt($curl_connectionCURLOPT_CONNECTTIMEOUT30);
            
    curl_setopt($curl_connectionCURLOPT_USERAGENT"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
            
    curl_setopt($curl_connectionCURLOPT_RETURNTRANSFERtrue);
            
    curl_setopt($curl_connectionCURLOPT_SSL_VERIFYPEERfalse);
            
    curl_setopt($curl_connectionCURLOPT_FOLLOWLOCATION1); 
    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.

    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:

    Code:
    user=<username>&pass=<password>&sublogin=1&a=login 
    Here is how:

    Code:
    /*
             * Login 
             */
            
    curl_setopt($curl_connectionCURLOPT_POSTFIELDS"user=<username>&pass=<password>&sublogin=1&a=login");
            
    curl_exec($curl_connection); 
    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:
    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.

    Code:
    /*
             * Submit Text now
             */
            
    curl_setopt($curl_connectionCURLOPT_POSTFIELDS"a=add&p=on&tags=codecall,tutorial&pasteinfo=This is a Tutorial&type=text");
            
    $result curl_exec($curl_connection); 
    $data is a variable set earlier which contains the submission text.

    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:

    Code:
    print_r(curl_getinfo($curl_connection)); 
    This should give you an idea of the problem. If you need any help or assistance, please feel free to ask me.

    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

  2. CODECALL Circuit advertisement

     
  3. #2
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Login and Submit Text to ASCIIBin (sample PHP and cURL script)

    Code:
    curl_setopt($curl_connection, CURLOPT_POSTFIELDS, "a=add&p=on&tags=codecall irc,log,chat,CCLogBot&pasteinfo={$textS}&type=text");
    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.

    Either way - good tut - maybe you should post the bot source too?

  4. #3
    Jordan Guest

    Re: Login and Submit Text to ASCIIBin (sample PHP and cURL script)

    Blaine: I covered that in the "NOTE" above:

    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().
    The urlencode function will properly encode &s for post/get submission. It is also part of the function at ASCIIBin.

    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?

  5. #4
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Posts
    2,487
    Rep Power
    33

    Re: Login and Submit Text to ASCIIBin (sample PHP and cURL script)

    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.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 9
    Last Post: 12-28-2010, 07:56 PM
  2. PHP Login with CURL
    By juice in forum PHP Development
    Replies: 6
    Last Post: 10-22-2010, 01:56 AM
  3. cURL login, go to other page and retrieve source
    By SimonBS in forum PHP Development
    Replies: 2
    Last Post: 10-21-2010, 01:20 PM
  4. Replies: 0
    Last Post: 10-10-2010, 11:06 AM
  5. Replies: 6
    Last Post: 08-07-2010, 07:01 PM

Tags for this Thread

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