And so, first you need to log in to the site http://mysite.ru/login.php and get cookies from there. This can be done like this:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://mysite.ru/login.php'); //url curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); // отсюда будут читаться куки curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); // сюда будут писаться куки curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_USERAGENT, 'Test UA'); curl_setopt($ch, CURLOPT_POST, true); // указываем что будет отправляться POST запрос ( Если он нужен для авторизации на сайте, конечно). curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=KryDos&password=qwerty'); $data = curl_exec($ch); curl_close($ch);
If the authorization was successful, then the cookie.txt file will store the cookies you want to send to http://www.mysite.ru/some.php.
Now, by analogy, do this:
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://mysite.ru/some.php'); //url curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); // отсюда будут читаться куки curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); // сюда будут писаться куки curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_USERAGENT, 'Test UA'); $data = curl_exec($ch); curl_close($ch);
Now the $ data variable will be what the browser would return when accessing mysite.ru/some.php.