Results 1 to 6 of 6
Sep 29, 2012, 19:49 #1
- Join Date
- Jul 2006
- 0 Post(s)
- 0 Thread(s)
logging in to another site with PHP+curl
I am trying to implement a new feature: the user of a PHP based site clicks on a link and is logged in into Perl based site. The logging in process itself works flawlessly. However, once I am in the Perl based site, once I click on any link, it asks me to log in again.
Upon further investigation. The code doesn't set cookies.
$username="john_smith"; $password="tOpsecret"; $url="https://somesite.com/login.html"; $cookiefile='/tmp/MasonX-Request-WithApacheSession-cookie'; $postdata = "mysite_username=".$username."&mysite_password=".$password; $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:126.96.36.199) Gecko/20070725 Firefox/188.8.131.52"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURL_COOKIEFILE, '');//dl curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookiefile); curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookiefile); curl_setopt ($ch, CURLOPT_REFERER, "https://whatsdown.nyi.net/news/"); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); $result = preg_replace("/<head>/i", "<head><base href='https://somesite.com/' />", $result, 1); echo $result;