My favorites
▼
|
Sign in
http-login-connect
HttpLoginConnect
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
loginconnecthttp.php
r4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
class HttpLoginConnect {
private $login;
private $user;
private $pass;
private $form_user;
private $form_pass;
private $parametro_opcional;
private $comprovar;
private $cookie_active;
private $cookie_value;
public function login($login)
{
$this->login = $login;
}
public function user_pass($usuario, $password)
{
$this->user = $usuario;
$this->pass = $password;
}
public function field_user($field_user)
{
$this->form_user = $field_user;
}
public function field_pass($field_pass)
{
$this->form_pass = $field_pass;
}
public function additional_parameter($par){
$this->parametro_opcional = $par;
}
public function check(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4');
curl_setopt($ch,CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($ch, CURLOPT_URL, $this->login);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HEADER,true);//Salida de las cabeseras
curl_setopt ($ch, CURLOPT_POST, true);
if(empty($this->parametro_opcional)){
curl_setopt ($ch, CURLOPT_POSTFIELDS, $this->form_user."=".$this->user."&".$this->form_pass."=".$this->pass);
}else{
curl_setopt ($ch, CURLOPT_POSTFIELDS, $this->form_user."=".$this->user."&".$this->form_pass."=".$this->pass."&".$this->parametro_opcional);
}
$header = curl_exec($ch);
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) == 302 || curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200){
preg_match_all("/Set-Cookie:\s*([\w\=]+)[\s\;\n]*/i", $header, $cookie_valor, PREG_SET_ORDER);
foreach ($cookie_valor as $cookie_valor){
$this->cookie_value .= $cookie_valor[1].";";
}
if(!empty($this->cookie_value)){
$this->comprovar = true;
}
}
curl_close($ch);
return $this->comprovar;
}
public function cookie_active($value){
if($value){
$this->cookie_active = true;
}else{
$this->cookie_active = false;
}
}
public function view_cookie(){
if($this->comprovar){
return $this->cookie_value;
}else{
return false;
}
}
public function get($site){
if($this->comprovar && $this->cookie_active){
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4');
curl_setopt($ch,CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($ch, CURLOPT_URL, $site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $this->cookie_value);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}else{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4');
curl_setopt($ch,CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($ch, CURLOPT_URL, $site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
}
}
?>
Show details
Hide details
Change log
r3
by elmafioso.edwin on Sep 1, 2010
Diff
Primera importación
Go to:
/trunk/loginconnecthttp.php
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 2906 bytes, 112 lines
View raw file
Powered by
Google Project Hosting