Page 1 of 1

PHP remote login via curl problem.

Posted: Fri Oct 22, 2010 6:35 am
by jake3340
Okay so i have around 100 forums I post a topic every day so people can download an ebook. The topic is always the same on every forum and currently I am doing it manually which is turning out to be quite annoying. I did some research on how to remotely do stuff with php and came up with some curl scripts which seem to work fine.

So the forums are all vbulletin so that should make it easier since the scripts all work the same. Now i am just starting the code and got stuck on the login part of the forum. I successfully managed to login into 1 forum using this code as an example.

Code: Select all

<?php
 
 
function curl_login($url,$data,$proxy,$proxystatus){
    $fp = fopen("cookie.txt", "w");
    fclose($fp);
    $login = curl_init();
    curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
    curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($login, CURLOPT_TIMEOUT, 40);
    curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
    if ($proxystatus == 'on') {
        curl_setopt($login, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($login, CURLOPT_HTTPPROXYTUNNEL, TRUE);
        curl_setopt($login, CURLOPT_PROXY, $proxy);
    }
    curl_setopt($login, CURLOPT_URL, $url);
    curl_setopt($login, CURLOPT_HEADER, TRUE);
    curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
    curl_setopt($login, CURLOPT_POST, TRUE);
    curl_setopt($login, CURLOPT_POSTFIELDS, $data);
    ob_start();      // prevent any output
    return curl_exec ($login); // execute the curl command
    ob_end_clean();  // stop preventing output
    curl_close ($login);
    unset($login);    
}                  
 
function curl_grab_page($site,$proxy,$proxystatus){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    if ($proxystatus == 'on') {
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
        curl_setopt($ch, CURLOPT_PROXY, $proxy);
    }
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_URL, $site);
    ob_start();      // prevent any output
    return curl_exec ($ch); // execute the curl command
    ob_end_clean();  // stop preventing output
    curl_close ($ch);
}  
curl_login("http://sitehere.com/
","other stuff bla bla","","off");
 


 
echo curl_grab_page('http://anothersitehere.com','','off');
 
?>
(I used the curl grab function just to see if it actually logs in)

Now what I was planning on doing is adding the 100 links of the forums I have to a mysql database and calling each link one by one logging in posting the topic etc... But the problem is since each login cookie is different for each forum i cannot simple change the link because it will not work. How can I get around this without going trough each forum retreiving and storing the cookie link (which is put instead of "other stuff bla bla" on the code example ontop) manually?

Re: PHP remote login via curl problem.

Posted: Fri Oct 22, 2010 8:13 am
by twinedev
What about contacting the admins of the forums to see about getting your account get set up to use an API to handle this, less messy without having to deal with cookies.

You also might get more help if you explain your reason behind such a script, as that might help some people decide to help you more. Myself, being a moderator on another forum with a lot of traffic, can't help but think of one main reason for something like this.

-Greg

Re: PHP remote login via curl problem.

Posted: Fri Oct 22, 2010 8:33 am
by jake3340
The forums use vbulletin, is there another way around it besides using the api ?