Execute PHP

This is a discussion on Execute PHP within the C++ Programming forums, part of the General Programming Boards category; What would be the best way to visit a list of URLs? It doesn't need to do anything but go ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    17

    Execute PHP

    What would be the best way to visit a list of URLs? It doesn't need to do anything but go to the site and increase a hitcounter. Would this be done with http requests or what? I've found a few things here and there but they all seem to be C++/MFC.

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    EDIT: Oops, this is C++. I though you wanted C# not C++/MFC, but I guess you want something on pure C++
    Try searching for appropriate libraries. Search like "http request C++" or "http C++". I know they are some good libraries that I had used in the past, but don't remember any right now.

    (Eh, will leave my original answer as well...)
    Here is code I use:
    Code:
    HttpWebResponse res = null;
                    StreamReader stream = null;
                    string html = String.Empty;
                    try
                    {
                        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(nextLink);
                        req.Method = "GET";
                        req.ContentLength = 0;
                        res = (HttpWebResponse)req.GetResponse();
                        stream = new StreamReader(res.GetResponseStream(), Encoding.ASCII);
                        html = stream.ReadToEnd();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        if (stream != null)
                            stream.Close();
                        if (res != null)
                            res.Close();                    
                    }
    which should work if by "hitcounter" you mean a counter that goes up everytime you visit a page.

    This is on System.Net

    Note that you don't need the stream = ... part since you don't care about reading anything. You need the response part though.

    I also want to state that you should always think about the moral behind doing things like this. Dunno exactly what the deal is, but had to give my thoughts.
    Last edited by C_ntua; 09-11-2010 at 06:48 PM.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > It doesn't need to do anything but go to the site and increase a hitcounter.
    Some people would call this click-fraud.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    17
    Quote Originally Posted by Salem View Post
    > It doesn't need to do anything but go to the site and increase a hitcounter.
    Some people would call this click-fraud.
    I won't be doing that (although I wouldn't consider that click-fraud at all). Like the title says, I'm looking to execute the PHP on a page (website needs to visited to do that) but I wanted to explain how it didn't need to actually do anything with the page, so I used that example.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is C++ or PHP the best option?
    By Yarin in forum Tech Board
    Replies: 7
    Last Post: 10-13-2009, 01:04 PM
  2. PHP installation
    By ssharish2005 in forum Tech Board
    Replies: 8
    Last Post: 11-23-2007, 08:42 PM
  3. php to execute c++ programs
    By kdoggfunkstah in forum C++ Programming
    Replies: 8
    Last Post: 07-26-2006, 12:26 PM
  4. Execute prog as other user
    By groorj in forum C Programming
    Replies: 2
    Last Post: 05-04-2005, 12:28 PM
  5. PHP on my Computer!
    By xxxrugby in forum Tech Board
    Replies: 4
    Last Post: 03-15-2005, 08:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21