3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Download { protected $db; protected $client; public $download; public $downloads; public $free_downloads; public $downloads_count; public $info; public $file; public $status; function __construct($db,$client) { $this->db = $db; $this->client = $client; } public function getDownloads() { if($result = $this->db->query("SELECT * FROM downloads WHERE client_id='".$this->db->real_escape_string($this->client['id'])."' ORDER BY id DESC")) { $return = array(); while($a = $result->fetch_assoc()) { $return[] = $a; } $this->downloads_count = $result->num_rows; $this->downloads = $return; $result->free(); } else { die('Database error: ('.$this->db->errno.') '.$this->db->error); } } public function getFreeDownloads() { if($result = $this->db->query("SELECT * FROM products WHERE cat='freedownload' AND active='yes'")) { $return = array(); while($a = $result->fetch_assoc()) { $return[] = $a; } $this->free_downloads = $return; $result->free(); } else { die('Database error: ('.$this->db->errno.') '.$this->db->error); } } public function getSingleDownload($id) { if($result = $this->db->query("SELECT * FROM downloads WHERE id='".$this->db->real_escape_string($id)."' AND client_id='".$this->db->real_escape_string($this->client['id'])."'")) { if($result->num_rows == 1) { $this->status = 'OK'; $this->download = $result->fetch_array(); } else { $this->status = 'Kon de download niet vinden.'; } $result->free(); } else { $this->status = 'Database error: ('.$this->db->errno.') '.$this->db->error; } } public function getProduct($id) { if($result = $this->db->query("SELECT * FROM products WHERE id='".$this->db->real_escape_string($id)."' AND cat='download' AND active='yes' OR id='".$this->db->real_escape_string($id)."' AND cat='freedownload' AND active='yes'")) { if($result->num_rows == 1) { $this->info = $result->fetch_array(); $this->status = 'OK'; } else { $this->info = null; $this->status = 'NOK'; } $result->free(); } else { $this->status = 'NOK'; die('Database error: ('.$this->db->errno.') '.$this->db->error); } } public function addDownload($product_id,$key,$key2,$com='no',$uses) { if($this->db->query("INSERT INTO downloads (client_id,product_id,key1,key2,com_use,uses,created) VALUES ( '".$this->db->real_escape_string($this->client['id'])."', '".$this->db->real_escape_string($product_id)."', '".$this->db->real_escape_string($key1)."', '".$this->db->real_escape_string($key2)."', '".$this->db->real_escape_string($com)."', '".$this->db->real_escape_string(uses)."', NOW() )")) { $this->status = 'OK'; } else { $this->status = 'Database error: ('.$this->db->errno.') '.$this->db->error; } } public function updateDownload($id) { if($this->db->query("UPDATE downloads SET used=used+1 WHERE id='".$this->db->real_escape_string($id)."'")) { $this->status = 'OK'; } else { $this->status = 'Database error: ('.$this->db->errno.') '.$this->db->error; } } public function download($id, $free=true) { if($free == true) { $this->getProduct($id); if($this->status = 'OK') { if($this->info['price'] > 0 || $this->info['cat'] != 'freedownload') { $this->status = 'Kon download niet ophalen'; } else { $this->file['name'] = 'MijnSweetGroups_FreeDownload_'.$this->info['id'].'_'.uniqid().'.zip'; $this->file['download'] = '/home/sweet/domains/sweetgroups.net/DOWNLOADS/'.$this->info['download_map'].'/'; $this->file['replace'] = array( '{%WEBSITES%}' => 'UNLIMITED', '{%UPDATE%}' => $this->info['description'], '{%LICENSE_CAT%}' => 'FREE', '{%LICENSE_KEY1%}' => 'NONE', '{%LICENSE_KEY2%}' => 'NONE' ); } } else { $this->status = 'Kon download niet ophalen'; } } else { $this->getSingleDownload($id); if($this->status = 'OK') { if($this->download['used'] < $this->download['uses']) { $this->getProduct($this->download['product_id']); if($this->status = 'OK') { $this->file['id'] = $id; if($this->info['download_map'] == '') { $this->info['download_map'] = 'unknown'; } if($this->download['com_use'] == 'yes') { $this->file['name'] = 'MijnSweetGroups_Download_'.$this->download['id'].'_Com.zip'; $this->file['download'] = '/home/sweet/domains/sweetgroups.net/DOWNLOADS/'.$this->info['download_map'].'_com'; $this->file['replace'] = array( '{%WEBSITES%}' => '1', '{%UPDATE%}' => $this->info['description'], '{%LICENSE_CAT%}' => 'SINGLE COMMERCIAL', '{%LICENSE_KEY1%}' => $this->download['key1'], '{%LICENSE_KEY2%}' => $this->download['key2'] ); } else { $this->file['name'] = 'MijnSweetGroups_Download_'.$this->download['id'].'.zip'; $this->file['download'] = '/home/sweet/domains/sweetgroups.net/DOWNLOADS/'.$this->info['download_map'].'/'; $this->file['replace'] = array( '{%WEBSITES%}' => '1', '{%UPDATE%}' => $this->info['description'], '{%LICENSE_CAT%}' => 'SINGLE', '{%LICENSE_KEY1%}' => $this->download['key1'], '{%LICENSE_KEY2%}' => $this->download['key2'] ); } $this->status = 'OK'; } else { $this->status = 'Kon download niet ophalen'; } } else { $this->status = 'Download is al reeds gebruikt of download is niet gevonden.'; } } else { $this->status = 'Kon download niet ophalen'; } } } public function getStatus($status) { switch($status) { case 'notused': return '<span class="grey">Niet gebruikt</span>'; break; case 'canceled': return '<span class="red">Geannuleerd</span>'; break; case 'pending': return '<span class="orange">Wordt gemaakt</span>'; break; case 'delivered': return '<span class="green">Geleverd</span>'; break; default: return '<span class="grey">Onbekend</span>'; } } } ?>
Output for 5.3.3 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.7
Output for 5.3.0 - 5.3.2
Strict Standards: Redefining already defined constructor for class Download in /in/igPlS on line 108

preferences:
124.15 ms | 401 KiB | 164 Q