1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

From PHP to C# and creating my own bot, how?

Discussion in 'C, C++, C#' started by ajushi, Jul 18, 2010.

  1. ajushi

    ajushi Registered Member

    Joined:
    May 27, 2010
    Messages:
    72
    Likes Received:
    19
    Occupation:
    Programmer
    Location:
    There's no place like 127.0.0.1
    Hi I'm currently a PHP programmer and with all the programs in the forums, I want to contribute my own as well but I don't know C# yet. I got a few questions:

    1. How did you learn C#? What book would you recommend?
    2. After learning C#, what should I do next?

    Thanks!
     
  2. kaidoristm

    kaidoristm Power Member

    Joined:
    Feb 13, 2009
    Messages:
    561
    Likes Received:
    726
    Occupation:
    Freelancer
    Location:
    Estonia
    Home Page:
    Why not to stay with php you dont need c# for that.
     
  3. ajushi

    ajushi Registered Member

    Joined:
    May 27, 2010
    Messages:
    72
    Likes Received:
    19
    Occupation:
    Programmer
    Location:
    There's no place like 127.0.0.1
    I could but (1) it would be great to do desktop apps for a change, (2) it's fun learning a new language and (3) for multi threading stuff
     
  4. kaidoristm

    kaidoristm Power Member

    Joined:
    Feb 13, 2009
    Messages:
    561
    Likes Received:
    726
    Occupation:
    Freelancer
    Location:
    Estonia
    Home Page:
  5. ajushi

    ajushi Registered Member

    Joined:
    May 27, 2010
    Messages:
    72
    Likes Received:
    19
    Occupation:
    Programmer
    Location:
    There's no place like 127.0.0.1
    Cool, you really made it with PHP? Do you have any tutorials that I can read on how to create one?
     
  6. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    If you are good in PHP learning c# won't be that hard. I started learning C# on my own without any ebooks or tutorials, just playing around and you find out that it's really simple after a while. Well it's been about 4 years now. But php for desktop is great too. Try both and you will see :)
     
  7. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    78
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    .NET is made for creating desktop apps and multi threading. i have serious questions about efficacy of using php for that type of programming task.

    to the OP, bottom line with .NET is that you really don't need a book. there's a wealth of information online about VB.NET/C#. search around for some of my other posts, there's some good information about getting yourself started in the BH arena with .NET languages. the MSDN site is an excellent source for documentation on all areas of the framework as well.

    one thread in particular you might find useful is:

    Code:
    http://www.blackhatworld.com/blackhat-seo/c-c-c/187505-first-c-bot.html
    there are some similarities in the structure of the syntax between C# and PHP as well, such as your array indicies using [ ] and whatnot.

    the way i learned C# was just by transitioning over from VB.NET. granted it's a much shorter jump since i was already familiar with many of the classes and namespaces that .NET leverages, so it was more just remembering syntax structure than anything else. for a new convert to the .NET framework some of the common namespaces you should familiarize yourself with are:

    System.IO
    System.Net
    System.Net.Sockets
    System.Threading
    System.Linq
    System.Text
    System.Text.RegularExpressions

    there's a huge list of other ones as well, but those are the ones that i tend to use the most.

    System.Linq is a newer one (started around framework 3.5) and allows you to do all kinds of nifty things with Predicates and Lambdas, and querying anything that implements IQueryable such as your lists and collections. for many functions where you are trying to find an object in a collection it completely removes the need for an enumerated looping construct.

    other features that i love in .NET are some of the OOP essentials. there's good support for polymorphism and inheritance. things like creating and implementing interfaces will help you reduce boiler plate code and make your code more re-useable.

    the .NET platform is also wide reaching. you can do windows, web, and mobile applications. from windows forms, windows presentation foundation, windows communication foundation, to the MVC, and rich client side internet apps with silverlight. all leveraging your framework.

    good luck. :)
     
    • Thanks Thanks x 2
  8. ajushi

    ajushi Registered Member

    Joined:
    May 27, 2010
    Messages:
    72
    Likes Received:
    19
    Occupation:
    Programmer
    Location:
    There's no place like 127.0.0.1
    That's an awesome comprehensive post smack! Thank you :)
    bbrez1: thanks for the encouragement :)
    kaidoristm: you're helpful as well! Thanks for pointing me that PHP is more than just webapps :)
     
  9. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    78
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    hey no problem man, i know making the jump to .NET can be daunting. i did it about 6 - 7 years ago from VB 6 and it was quite a steep learning curve. in some ways it still is. there is so much that .NET covers that it is a really great platform to delve in to, and with all the new things they add each release of the framework it just keeps improving.

    good luck with the migration. don't forget that you have an amazing amount of community support online through loads of blogs, message boards, msdn, etc...

    welcome to the dark side of proprietary microsoft programming languages ;)
     
  10. Bots_Do_it_Faster

    Bots_Do_it_Faster Registered Member

    Joined:
    Jun 28, 2010
    Messages:
    64
    Likes Received:
    77
    Occupation:
    Web Developer php and c#
    Location:
    South Florida
    If you are still interested in an a pdf to help learn C# i recommend googling:

    "programmersheaven csharp ebook"

    First link should the an ebook from programmersheaven that is free.

    It starts with with basics and goes right on through the advanced.

    I would say the question of which is better is the wrong way to look at it. Building bots in PHP or C# have there place. For example years ago before I knew C# I only made PHP bots. I learned all the tricks and knew how to battle my way through the nastiest of curl commands both commandline and using the php-curl module. I remember leaving a bot running for a week or more to pull a list of emails from a directory site of just 100k or so. Yes I did finally improve my skills to simulate multi threading by using curl, and I thought I was on top fo the world. Then came the day I built my first C# bot and my jaw hit the desk. I could do simple stuff like sort emails out of csv files that would nomarly take a few minutes to run in php and it would finish in just a few seconds.

    These days I write any of my bots that I don't need to act as a webservice in C# and the rest in PHP. A good example of a case to use php would be for a Keyword Bot. It would check the referring string for the keyword that was typed in google to get to your site. Take that keyword and check against the database of content pages you have and if you don't have a current page you set the bot to go harvest content and do a basic spin and create a new content page. Also when you create the new page you are updating your site map to make sure it is indexed and then you have your bot login to a few of your favorite places to dump part of your content for backlinks and you have the site that keeps on growing on its own.

    When you start out making your first C# bots there are 2 main methods you can use. The first is using webBrowser and is what most beginners start with. Basically you are putting and IE browser element in your application and are programatically remote controling this browser. The advantage is it will handle javascript, cookies, and the technical parts of posting forms automatically. The downside is it is slow and there are browser security issues uploading files, and you can't multithread. The webBrowser element runs on the UI thread so the screen will freeze up with lot of heavy processing. The second method is the httpRequest httpResponse. People that have any exprience making C# bots will use this method. The learning curve is a little steeper, but it gives you a lot more control of how you post to the page down to the way you form your headers. This method lends itself very easily to multithreading. I recommend if you multithread to look at ThreadPool. It will handle all the dirty work like controling the number of threads running concurrently. Also when you start using httpRequest for posting to forms I recommend getting Fiddler2. It is a free packet sniffer and IMHO is much easier to trouble shoot with than wireshark and the likes. The reason is it doesn't have all the other network tools that wireshark has and you can focus on checking out your headers and parameter data rather than try and be a sytem admin with wireshark.

    At the end of the day if you are wanting to learn you should check out some tutorials, but nothing beats jumping in and just writing some code to see what it can do.

    Good luck
     
  11. kuzmanin

    kuzmanin Regular Member

    Joined:
    Jul 17, 2010
    Messages:
    386
    Likes Received:
    45
    stay with php for bot and do other things with C# :)