-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
167 lines (160 loc) · 4.97 KB
/
functions.php
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
//Código escrito por Tony Cárdenas @shishanyu 2016
//Publicado bajo la GNU GENERAL PUBLIC LICENSE
class clean {
public static function phone (&$string){
$string = preg_replace('/[^0-9]+/', '', $string);
return $string;
}
public static function email (&$string){
$string = filter_var($string, FILTER_SANITIZE_EMAIL);
return $string;
}
public static function name (&$string){
//$string = preg_replace('/[\n\r\\\\"\']+/', '', $string);
$string = utf8_decode($string);
$string = preg_replace('/[^A-Za-z\s\p{L}\.]+/', '', $string);
$string = filter_var($string, FILTER_SANITIZE_STRING);
return $string;
}
public static function number (&$string){
$string = filter_var($string, FILTER_SANITIZE_NUMBER_INT);
return $string;
}
public static function addressnumber (&$string){
$string = preg_replace('/[^0-9A-Za-z]+/', '', $string);
return $string;
}
public static function text (&$string){
$string = filter_var($string, FILTER_SANITIZE_MAGIC_QUOTES);
return $string;
}
}
class validate {
public static function phone ($string){
if(strlen($string) != 10){
die("Deben ser 10 números exactos en el teléfono");
return false;
} else if (filter_var($string, FILTER_VALIDATE_INT) === false){
die ("Contiene caracteres que no son números");
return false;
}
return $string;
}
public static function password ($string){
if(strlen($string) < 6){
die("Deben ser al menos 6 caracteres en la contraseña");
return false;
}
return $string;
}
public static function email ($string){
if (filter_var($string, FILTER_VALIDATE_EMAIL) === false){
die ("El correo no es válido");
return false;
}
return $string;
}
public static function name ($string,$what="El nombre"){
$string = utf8_decode($string);
if (filter_var($string, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/[^A-Za-z\s\p{L}]/")))){
die ("$what $string contiene caracteres no válidos");
return false;
}
if(strlen($string) < 2){
die ("$what contiene menos de 2 caracteres");
}
return $string;
}
public static function addressnumber ($string){
if (filter_var($string, FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/[^0-9A-Za-z]/")))){
die ("Sólo se aceptan letras simples y números");
return false;
}
return $string;
}
public static function text ($string){
$original = $string;
$string = filter_var($string, FILTER_SANITIZE_MAGIC_QUOTES);
if($original != $string){
die ("Esta cadena de texto contiene caracteres no válidos por ejemplo: ' " \ ");
return false;
}
return $string;
}
}
class db {
private $user = "usuariodeprueba";
private $pass = "hASD4l-=¿madCU8";
private $database = "hackerid";
private $host = "localhost";
private $dbcon = NULL;
public function finish (){
if($this->dbcon != NULL){
$con = $this->dbcon;
$con->close();
$this->dbcon = NULL;
}
return false;
}
public function start (){
$this->finish();
$this->dbcon = new mysqli($this->host, $this->user, $this->pass, $this->database);
$con = $this->dbcon;
$con->set_charset("utf8");
if($con->connect_errno) {
printf("Falló la conexión: %s\n", $con->connect_error);
return false;
}
return true;
}
public function query($query){
if($this->dbcon == NULL){
$this->start();
}
$con = $this->dbcon;
$result = $con->query($query);
return $result;
}
public function lastID(){
if($this->dbcon == NULL){
return false;
}
$con = $this->dbcon;
$result = $con->insert_id;
return $result;
}
}
class email {
public static function sendSystemMail($recipient,$title="",$message="",$name=""){
require_once './phpmailer/class.phpmailer.php';
require_once './phpmailer/class.smtp.php';
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
// $mail->IsSMTP(); // telling the class to use SMTP
try {
$sender = "[email protected]";
$senderName = "HackerID Bot";
// $mail->Host = "radio.bembahost.net"; // SMTP server
$mail->CharSet = 'UTF-8';
/*
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = $sender; // SMTP account username
$mail->Password = ""; // SMTP account password
*/
$mail->AddReplyTo("$sender", 'HackerID Bot');
$mail->AddAddress("$recipient", "$name");
$mail->SetFrom("$sender", "$senderName");
$mail->Subject = "HackerID: $title";
$mail->AltBody = "$message"; // optional - MsgHTML will create an alternate automatically
$mail->MsgHTML($mail->AltBody);
$mail->Send();
} catch (phpmailerException $e) {
die($e->errorMessage());
} catch (Exception $e) {
die($e->getMessage());
}
}
}
?>