Page 1 of 1

cURL PHP - Login to Website

Posted: Sat Mar 10, 2012 10:59 pm
by Losdivinos
Hi!

I need to login to a site with cronjobs every 15 minutes.
I guess the only way to do it is to use cURL PHP function.

For me, it is quite advanced, so I would like help, if anybody knew how to do it.

The page it should login at is NOT on my site. I also has to do a header("location: balbalbal"); afterwards.

Thanks in Advance!

Rasmus

Re: cURL PHP - Login to Website

Posted: Sun Mar 11, 2012 3:23 pm
by Losdivinos
Bump :)

Re: cURL PHP - Login to Website

Posted: Tue Mar 13, 2012 2:30 pm
by Bink
Hi ;)

Code: Select all

  function login($url,$PostFields)
   {
    $url = curl_init($url);  
    curl_setopt($url, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($url, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($url, CURLOPT_FOLLOWLOCATION, FALSE);
    curl_setopt($url, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookies.txt');
    curl_setopt($url, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookies.txt');
    curl_setopt($url, CURLOPT_POSTFIELDS, $PostFields);
    $result=curl_exec($url);
    curl_close($url);
   }

example:
$PostFields="name=$name&pass=$password&submit=login";
login('http://somewebsite.com/login',$PostFields);