Convert C++ to PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Convert C++ to PHP

Post by Vegan »

A while ago I wrote a short program in C++....

Code: Select all

 
#include "windows.h" 
#include <string> 
 
std::string arg; 
std::string sitemap = "/sitemap.xml"; 
bool hres;
 
const int sites = 4; 
const int hosts = 6; 
 
std::string URLlist[sites] = { 
    "computer-chess.dyndns.biz", 
    "contract-developer.dyndns.biz", 
    "econ.dyndns.biz", 
    "vegan.dyndns.biz", 
}; 
 
std::string API[hosts] = { 
    "webmaster.live.com/webmaster/ping.aspx?siteMap=", 
    "search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=", 
    "www.google.com/webmasters/tools/ping?sitemap=",
    "submissions.ask.com/ping?sitemap=",
    "api.moreover.com/ping?sitemap=",
    "www.bing.com/webmaster/ping.aspx?sitemap="
}; 
 
void main() { 
    for (int i = 0; i < hosts; i++) { 
        for (int j = 0; j < sites; j++) { 
            arg = API[i]; 
            arg += "http://"; 
            arg += URLlist[j]; 
            arg += sitemap; 
            ShellExecute(NULL, "open", arg.c_str(), NULL, NULL, SW_SHOWNORMAL); 
            Sleep(10000); // 10 seconds, so servers do not balk
        } 
    };
    // Zap the browser, easy as its the foreground task, no need to hunt it down
    hres = PostMessage(GetForegroundWindow(), WM_CLOSE, NULL, NULL);
} 
 
I thought, why not post a form page with this bolted onto the POST. I am new to PHP.

A form is easy in any Windows Web tool. They all have menu tools to pic from.

So given a form with say a variable called user_URL or something like that, or even the default name or whatever. Once I have that variable I wanted to emulate the behaviors as above.

The program opens a browser in Windows and assigns the given URL to HTTP GET. The return page is a brief pass/fail. The sleep call is to slow the process down as the operators' server cannot handle the speed.

I do not really need to see the result, just get each URL and dump it. With sufficient delays it works fine. I used a browser call to "see" errors so I could debug the code.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Convert C++ to PHP

Post by AbraCadaver »

Just a quick example. Needs prettying, variable validation etc...

Code: Select all

<?php
if(isset($_POST['user_url'])) {
 
    $user_url = $_POST['user_url'];
    $sitemap = "/sitemap.xml";
    
    $API = array(
        "webmaster.live.com/webmaster/ping.aspx?siteMap=",
        "search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid=YahooDemo&url=",
        "www.google.com/webmasters/tools/ping?sitemap=",
        "submissions.ask.com/ping?sitemap=",
        "api.moreover.com/ping?sitemap=",
        "www.bing.com/webmaster/ping.aspx?sitemap=",
    );
    
    foreach ($API as $api_url) {
        $arg  = "http://";
        $arg .= $api_url;
        $arg .= "http://";
        $arg .= $user_url;
        $arg .= $sitemap;
 
        echo $arg . "\n";   
        readfile($arg);
        flush();
        sleep(10); // 10 seconds, so servers do not balk
    };
} else {
    echo '<form method="post">'
        .'URL <input type="text" name="user_url"> <input type="submit" name="submit" value="Submit">'
        .'</form>';
}?>
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: Convert C++ to PHP

Post by daedalus__ »

you did his work for him. :roll:
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Convert C++ to PHP

Post by AbraCadaver »

daedalus__ wrote:you did his work for him. :roll:
Was bored...
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Vegan
Forum Regular
Posts: 574
Joined: Fri Sep 05, 2008 3:34 pm
Location: Victoria, BC
Contact:

Re: Convert C++ to PHP

Post by Vegan »

Thank you, I am not super skilled in PHP but I am slowly getting a grip on it.
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
Post Reply