1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to make a php robot that can log in?

Discussion in 'PHP' started by QueenZ, Feb 22, 2012.

  1. QueenZ

    QueenZ Peon

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #21
    not sure what you meant.... regex the one time code and then submit it with the POST?
     
    QueenZ, Feb 22, 2012 IP
  2. QueenZ

    QueenZ Peon

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #22
    looks like that hidden field is there for security purposes, is there a workaround?
     
    QueenZ, Feb 22, 2012 IP
  3. #23
    Right this 100% works tested on my host:
    
    <?php
    function curl($url, $post = NULL)
    {
        $ch = curl_init();
    
        $cookies = "cookie.txt";
        $post = is_null($post) ? '' : $post;
            
        if ($cookies != '')
        {
            if (substr(PHP_OS, 0, 3) == 'WIN')
            {
                $cookies = str_replace('\\','/', getcwd().'/'.$cookies);
            }
            curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookies);
            curl_setopt ($ch, CURLOPT_URL, $url);
            if ($post != NULL)
            {
                curl_setopt ($ch, CURLOPT_POST, 1);
                curl_setopt ($ch, CURLOPT_POSTFIELDS, $post);
            }
            curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookies);
            curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 300);
            curl_setopt ($ch, CURLOPT_TIMEOUT, 300);
            curl_setopt ($ch, CURLOPT_MAXREDIRS, 3);
            
            if(curl_exec($ch) === false)
            {
                curl_close ($ch);
    			return false;
            }
            else
            {
                $html = curl_exec ($ch);
    			curl_close ($ch);
    			return $html;
            }
        }
    }
    
    
    //**** Login *****//
    curl("http://localhost/wordpress/wp-login.php", "log=admin&pwd=xx1212");
    //echo $loggedin 
    
    //**** Addin New User *****//
    $adduser = curl("http://localhost/wordpress/wp-admin/user-new.php");
    
    preg_match('/name="_wpnonce_create-user" value="([a-z|0-9]+)"/', $adduser, $matches);
    
    // role: 	subscriber, administrator, editor, author or contributor
    $post = "action=createuser&_wpnonce_create-user=".$matches[1]."&_wp_http_referer=/wp-admin/user-new.php";
    $post .= "&user_login=tester" . "&email=tester@gmail.com" . "&first_name=" . "&last_name=";
    $post .= "&url=" . "&pass1=interestingpass" . "&pass2=interestingpass" . "&role=subscriber" . "&createuser=Add New User ";
    
    $adduser = curl("http://localhost/wordpress/wp-admin/user-new.php", $post);
    echo $adduser;
    ?>
    
    PHP:
     
    Lee Stevens, Feb 22, 2012 IP
  4. QueenZ

    QueenZ Peon

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #24
    that worked! You're a genius! I just have one question... doesn't it generate a new security key every time you load the page? So how did you get to load it for regex and then load it again to submit it?
     
    QueenZ, Feb 22, 2012 IP
  5. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #25
    Yes a new security code will be generated each time, because i loaded it once here:
    
    $adduser = curl("http://localhost/wordpress/wp-admin/user-new.php");
    
    PHP:
    Then i used post here:
    
    $adduser = curl("http://localhost/wordpress/wp-admin/user-new.php", $post); // see the , $post on the end.
    
    PHP:
    First gets the source then the second send the post so it doesn't reload the source.
     
    Lee Stevens, Feb 22, 2012 IP
    QueenZ likes this.
  6. QueenZ

    QueenZ Peon

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #26
    oooh, I see. That is neat! Thank you SO MUCH!!
     
    QueenZ, Feb 22, 2012 IP
  7. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #27
    Haha, your welcome we got there in the end!!
     
    Lee Stevens, Feb 22, 2012 IP
  8. QueenZ

    QueenZ Peon

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #28
    hehe, Yepp :)
     
    QueenZ, Feb 22, 2012 IP