-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicAuthentication.php
More file actions
50 lines (50 loc) · 1.56 KB
/
BasicAuthentication.php
File metadata and controls
50 lines (50 loc) · 1.56 KB
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
<?php
class BasicAuthentication{
private $pUsername = "USERNAME";
private $pPwd = "PASSWORD";
private $mUrl = "URL";
private $authentication = "";
public function __construct(){
$this->authentication = "Basic ".base64_encode($this->pUsername.":".$this->pPwd);
}
/*
GET XML Data from Server with Basic Authentication
*/
public function GetAllProductsByParts($index,$count){
$link = "GetAllProductsByParts/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->mUrl.$link.$index."/".$count);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,60);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$this->authentication));
$sonuc= curl_exec($ch);
$new = simplexml_load_string($sonuc);
$con = json_encode($new);
$a = json_decode($con,true);
return $a;
}
/*
GET Image from Server with Basic Authentication
*/
public function DownloadProductImageByCode($code,$folder="images/"){
$link = "DownloadProductImage/ByCode/";
if(strpos($code,"/"))
$code = substr($code,strripos($code, "/"));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->mUrl.$link.$code);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$this->authentication));
$sonuc= curl_exec($ch);
curl_close($ch);
$img = FCPATH.$folder.$code.".jpg";
if(file_exists($img)){
unlink($img);
}
$fp = fopen($img,'x');
fwrite($fp, $sonuc);
fclose($fp);
}
}
?>