Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
Is this something you are doing for you only? As a convenience? –  s_ha_dum Jan 5 '13 at 15:22
add comment

1 Answer

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?)

share|improve this answer
    
Hi,Thanks for the reply , have you have any code about auto authentication for wordpress ? –  jothikannan Jan 5 '13 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. –  Mridul Aggarwal Jan 5 '13 at 15:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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