Cannot login to wordpress with curl and php -



Cannot login to wordpress with curl and php -

i trying create function in php using curl, logs local wordpress, getting trouble.

i have function:

function wordpresslogin($username, $password, $loginurl, $visiturl, $useragent, $cookiefile) { if (!function_exists('curl_init') || !function_exists('curl_exec')) { echo 'curl not available!'; } //$postdata = "log=". $login_user ."&pwd=" . $login_pass . "&wp-submit=log%20in&redirect_to=" . $visit_url; $postdata = "log=$username&pwd=$password&wp-submit=log+in&redirect_to=$visiturl&testcookie=1"; $ch = curl_init(); //url utilize login curl_setopt($ch, curlopt_url, $loginurl); //activate cookiejar //curl_setopt($ch, curlopt_cookiesession, true); //set cookie curl_setopt($ch, curlopt_cookiejar, $cookiefile ); //no need ssl curl_setopt($ch, curlopt_ssl_verifypeer, false); //user agent curl_setopt($ch, curlopt_useragent, $useragent); //timeout curl_setopt($ch, curlopt_timeout, 60); //follow redirection curl_setopt($ch, curlopt_followlocation, 1); //return or echo curl_setopt($ch, curlopt_returntransfer, 1); //referer curl_setopt($ch, curlopt_referer, $loginurl); //post curl_setopt($ch, curlopt_postfields, $postdata); curl_setopt($ch, curlopt_post, 1); //save result content $content = curl_exec($ch); //close curl curl_close($ch); //return content echo $content; } //testing $username = 'admin'; $password = 'admin'; $loginurl = 'http://localhost/wordpress/wp-login.php'; $visiturl = urlencode('http://localhost/wordpress/wp-admin'); $useragent = 'mozilla/5.0 (x11; linux x86_64; rv:30.0) gecko/20100101 firefox/30.0'; $cookiefile = '/tmp/cookie.txt'; wordpresslogin($username, $password, $loginurl, $visiturl, $useragent, $cookiefile);

the $postdata variable, has username , password, of wordpress. getting error wordpress when run error: cookies blocked or not supported browser. must enable cookies utilize wordpress.

even thought i've set cookiejar it, this, , don't know why.

if take out testcookie=1 parameter $postdata variable it's showing me blank page. i've tested script yesterday, without testcookie parameter , worked, i've reinstalled today wordpress, , cookie error.

so, in conclusion, if leave testcookie parameter, it's showing me error. if take out, it's showing me blank page.

and ideas ?

php wordpress cookies curl

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -