php - Log in with cURL and echo response with cookie -


i trying write "auto-login" script, uses curl log in specific site , echoing response, user can "bypass" login. (for example, grant one-time logins etc)

obviously, using following method, cookie stored on server, not on client, in cookie.txt.

i've tried setting $_cookie, won't work, since urls (actually subdomains) of auto-login script , service logged into, different.

login works fine. see screen if logged in, clicking link requires login again.

any ideas? thanks

the code i've used auto-login:

<?php $username="email@domain.com";  $password="password";  $url="http://sub.domain-to-login.com/index.php/sessions/login";  $cookie="cookie.txt";   $postdata = "email=".$username."&password=".$password.'&btn_login=login';   $ch = curl_init();  curl_setopt ($ch, curlopt_url, $url);  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, 1);  curl_setopt ($ch, curlopt_cookiejar, $cookie);  curl_setopt ($ch, curlopt_referer, $url);   curl_setopt ($ch, curlopt_postfields, $postdata);  curl_setopt ($ch, curlopt_post, 1);  $result = curl_exec ($ch);  curl_close($ch); echo $result;   ?> 

i guess need replace links (in $result) http://sub.domain-to-login.com/index.php/stuff http://mysite.com?url=http://sub.domain-to-login.com/index.php/stuff , using curl download site again. cannot set cookie diffrent site.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -