views:

99

answers:

2

Hello,

I'm going to improve one of my new projects and one of the features that I want to add is the possibility to post a new thread in a phpBB forum board, but it's possible to do this? If it is, how can I do this? Thanks.

+1  A: 

I wont write all the code for you, but I can dump a couple of things I've built that work well.

One way is to create a webbrowser control, and create something like this:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            HtmlDocument doc = null;
            doc = webBrowser1.Document;

            //Find login text box and write user name  
            HtmlElement login = doc.GetElementById("username_or_email");
            login.InnerText = this.login;

            //Find password text box and write password
            HtmlElement password = doc.GetElementById("session[password]");
            password.InnerText = this.password;

            // go to the submit button
            webBrowser1.Document.GetElementsByTagName("input")[5].Focus();
            SendKeys.Send("{ENTER}");

        }

Another way is to use http requests (not as likely to work reliably with phpBB)

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(twitterUrl + userID + ".xml");
                string Credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(this.login + ":" + this.password));

                request.Method = "POST";
                request.ContentType = "application/xml";
                request.AllowWriteStreamBuffering = true;
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; GTB6; SLCC1; .NET CLR 2.0.50727;";
                request.Headers.Add("Authorization", "Basic " + Credentials);

                HttpWebResponse HttpWResp = (HttpWebResponse)request.GetResponse();

                string response = HttpWResp.StatusCode.ToString();
        HttpWResp.InitializeLifetimeService();
        HttpWResp.Close();    

       return response;

The code above is used to log into twitter. You can modify either of those to suit your tastes. Remember phpBB is likely to use captcha and session validation to prevent exactly what you're trying to do.

Jeremy Morgan
+2  A: 
  1. You can accomplish this with a simple insert statement into the phpBB database, however, in order to ensure that all things go smoothly, you need to make sure that you also insert any other rows phpBB would otherwise insert for a new thread (look up documentation/source code for that).

    In addition, you would need to make sure you entered the proper IDs for w/e unique IDs are required in the insert (like UserID for the user creating the thread)

  2. Another method is to create a separate php file that exposes the create thread function (w/e it may be called) that phpBB uses to create the new thread. You would allow POST/GET (POST is more secure) to the php file and would then run an HTTP POST/GET request from C#.

    In your new php file, would need some type of authorization to ensure that no one else is posting/requesting the page. You can hard code a specific field name that must contain a specific access key, so that any incoming posts/gets that don't have it will be ignored.

The second method, imo, is better because it lets phpBB do all the hard work, you just need to wire it up correctly.

However, with the 2nd method, you might have security issues and phpBB might not even allow what you're trying to do. (I think to call certain methods, the page needs to have DEFINE("IN", "PHPBB") or something of the sort, which places more constraints on what you can do.

To start off, I would look around phpBB support sites and see if the 2nd part is even possible and figure out if calling the functions is something that can easily be done.

Baddie