Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Created January 19, 2016 14:20
Show Gist options
  • Select an option

  • Save VictorFursa/744f5c12f61a0c5a14f4 to your computer and use it in GitHub Desktop.

Select an option

Save VictorFursa/744f5c12f61a0c5a14f4 to your computer and use it in GitHub Desktop.
<?php
class Curl{
private $agent = 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)';
private $curl;
private $cookiefile;
private $login='';
function __construct($login_url){
$this->curl = curl_init($login_url);
curl_setopt($this->curl, CURLOPT_URL,$login_url); //указываем адрес страницы
curl_setopt($this->curl, CURLOPT_USERAGENT, $this->agent); //указываем заголовок User-Agent
curl_setopt($this->curl, CURLOPT_REFERER, $login_url);//т.е. нужно указать адрес страницы на которой находится форма
$this->cookiefile = tempnam('/var/www/alcoholic.com/', __DIR__."/cookies.txt");
curl_setopt($this->curl, CURLOPT_COOKIEFILE, $this->cookiefile);
curl_setopt($this->curl, CURLOPT_COOKIEJAR, $this->cookiefile);
}
function setRefer($refer){
return curl_setopt($this->curl, CURLOPT_REFERER, $refer);
}
function close(){
curl_close($this->curl); //завершает сеанас
}
function sendPostForm($Data){
curl_setopt($this->curl, CURLOPT_POST, 1); //добавляем строку с post данными
curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($Data));
}
function exec(){
return curl_exec($this->curl);
}
function setReturnTransfer($value){
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, $value);
}
function getPage($url){
$this->curl = curl_init($url);
curl_setopt($this->curl, CURLOPT_URL,$url);
curl_setopt($this->curl, CURLOPT_REFERER, $url);
$out = curl_exec($this->curl);
echo $out;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment