0

i need to integrate a wordpress login into my php website, for the purpose of single login to access my website and wordpress blog also, i have used some codes using curl it is logged in the user, and there after it redirects into my home page , after i have to access my wordpress blog it doesn't authenticate me, it say me to login,

am using following code

$username="admin";
$password="blog";
$url="http://wordpressblogURL/";
$cookie="cookie.txt";

$postdata = "log=". $username ."&pwd=". $password ."&wp-submit=Log%20In&redirect_to=". $url ."blog/wordpress/wp-admin/&testcookie=1";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url . "blog/wordpress/wp-login.php");

curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_REFERER, $url . "blog/wordpress/wp-login.php");

curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
curl_close($ch);
echo $result;

exit;

please let me know what is wrong with this code, also in cookie.txt something written every time am login into my website

Thanks in advance

1
  • Is this something you are doing for you only? As a convenience?
    – s_ha_dum
    Commented Jan 5, 2013 at 15:22

1 Answer 1

1

Wordpress uses cookie based authentication. When you log into wordpress using curl, wordpress is authenticating the server(which ran the curl script) & not your client. so when you visit wordpress using your browser(client), it's not authenticated.

For the solution, you could use wordpress hooks to automatically authenticate the user to your site just after they authenticate themselves to wordpress. Then whenever a user comes to your site, you could just redirect them to wordpress login url for authentication.

Another solution is to override the authentication functions in wordpress. All of the authentication functions in wordpress are directly or indirectly pluggable. When you override them instead of checking if the user has the correct cookie set, you will check if the user has logged in on the other site (Maybe use a shared database?)

2
  • Hi,Thanks for the reply , have you have any code about auto authentication for wordpress ? Commented Jan 5, 2013 at 15:34
  • No one can help you with code. It totally depends on your other site. Most probably you'll have to write the code yourself. Commented Jan 5, 2013 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.