· 5 years ago · Apr 07, 2020, 04:42 AM
1<?php
2use PHPMailer\PHPMailer\PHPMailer;
3use PHPMailer\PHPMailer\Exception;
4
5require_once __DIR__ . '/../../vendor/autoload.php';
6require_once __DIR__ . '/../../vendor/phpmailer/phpmailer/src/PHPMailer.php';
7require_once __DIR__ . '/../../vendor/phpmailer/phpmailer/class.phpmailer.php';
8
9$title = 'Register';
10
11include('../config/dbconfig.php');
12include ('header.php');
13
14if(isset($_SESSION['user_id']))
15{
16 header("location:index.php");
17}
18
19$message = '';
20
21if(isset($_POST["register"]))
22{
23
24 $query = "
25 SELECT * FROM users_test
26 WHERE user_email = :user_email
27 ";
28 $statement = $conn->prepare($query);
29 $statement->execute(
30 array(
31 ':user_email' => $_POST['user_email']
32 )
33 );
34 $no_of_row = $statement->rowCount();
35 if($no_of_row > 0)
36 {
37 $message = '<label class="text-danger">Email Already Exits</label>';
38 }
39 else
40 {
41 $uPic = $imgFile = $tmp_dir = $imgSize = ''; //provato anche così
42
43
44 $first_name = htmlentities(trim($_POST['first_name']),ENT_QUOTES);
45 $last_name = htmlentities(trim($_POST['last_name']),ENT_QUOTES);
46 $user_name = htmlentities(trim($_POST['user_name']),ENT_QUOTES);
47 $user_email = htmlentities(trim($_POST['user_email']),ENT_QUOTES);
48 $user_password = htmlentities(trim($_POST['user_password']),ENT_QUOTES);
49 $uPic = htmlentities(trim($_POST['uPic']), ENT_QUOTES);
50 $role_id = htmlentities(trim($_POST['user_role']), ENT_QUOTES);
51 /////*****************************************************************
52
53 $uPic = htmlentities(trim($_FILES['uPic']), ENT_QUOTES); // Undefined index: uPic in C:\xampp\htdocs.. on line 53
54
55 $imgFile = $_FILES['uPic']['name']; // Undefined index: uPic in C:\xampp\htdocs.. on line 57
56 $tmp_dir = $_FILES['uPic']['tmp_name']; // Undefined index: uPic in C:\xampp\htdocs.. on line 58
57 $imgSize = $_FILES['uPic']['size']; // Undefined index: uPic in C:\xampp\htdocs.. on line 59
58
59 //## => ho messo la dir: uploads per semplificarmi la vita!!
60 $upload_dir = 'uploads/'.$user_name; // upload directory
61
62 mkdir($upload_dir, 0777);
63
64 $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension
65
66 // valid image extensions
67 $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions
68
69 // rename uploading image
70 $userPic = $imgFile;
71 // allow valid image file formats
72 if(in_array($imgExt, $valid_extensions)){
73 // Check file size '5MB'
74 if($imgSize < 5000000) {
75 move_uploaded_file($tmp_dir,$upload_dir.'/'.$userPic);
76 }
77 else{
78 $errMSG = "Sorry, your file is too large.";
79 }
80 }
81 else{
82 $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
83 }
84
85 /////*****************************************************************
86 $options = array("const"=>4);
87 $user_encrypted_password = password_hash($user_password, PASSWORD_BCRYPT, $options);
88 $user_activation_code = md5($user_name);
89 $insert_query = "
90 INSERT INTO users_test
91 (role_id, first_name, last_name, user_name, user_email, user_password, user_activation_code, user_email_status, profile_picture)
92 VALUES (:role_id, :first_name, :last_name, :user_name, :user_email, :user_password, :user_activation_code, :user_email_status, :uPic)
93 ";
94 $statement = $conn->prepare($insert_query);
95 $statement->execute(
96 array(
97 ':role_id' => $_POST['role_id'],
98 ':first_name' =>$_POST['first_name'],
99 ':last_name' => $_POST['last_name'],
100 ':user_name' => $_POST['user_name'],
101 ':user_email' => $_POST['user_email'],
102 ':user_password' => $user_encrypted_password,
103 ':user_activation_code' => $user_activation_code,
104 ':user_email_status' => 'not verified',
105 // ':uPic' => $_POST['uPic'] // il nome del file deve provenire da $userPic
106 ':uPic' => $userPic
107 )
108 );
109 $result = $statement->fetchAll();
110 if(isset($result))
111 {
112 $base_url = "https://chiab-gigi.it/";
113 $mail_body = "
114 <p>Hi ".$_POST['user_name'].",</p>
115 <p>Thanks for Registration.</p>
116 <p> Your password is ".$user_password."</p>
117 <p>This password will work only after your email verification.</p>
118 <p>Please Open this link to verified your email address </p>
119 <p>".$base_url."email_verification.php?activation_code=".$user_activation_code."</p>
120 <p>Best Regards,<br />chiab-gigi.it</p>
121 ";
122
123
124 $mail = new PHPMailer;
125 $mail->SMTPOptions = array ('ssl'=>array ('verify_peer'=>false,'verify_peer_name'=>false,'allow_self_signed'=>true));
126 $mail->debug = 1;
127 $mail->IsSMTP(); //Sets Mailer to send message using SMTP
128 $mail->Host = 'smtp.gmail.com'; //Sets the SMTP hosts of your Email hosting, this for Godaddy
129 $mail->Port = '587'; //Sets the default SMTP server port
130 $mail->SMTPAuth = true; //Sets SMTP authentication. Utilizes the Username and Password variables
131 $mail->Username = '**********@gmail.com'; //Sets SMTP username
132 $mail->Password = '***********'; //Sets SMTP password
133 $mail->SMTPSecure = 'tls'; //Sets connection prefix. Options are "", "ssl" or "tls"
134 $mail->From = '***********@gmail.com'; //Sets the From email address for the message
135 $mail->FromName = 'chiab-gigi'; //Sets the From name of the message
136 $mail->AddAddress($_POST['user_email'], $_POST['user_name']); //Adds a "To" address
137 $mail->WordWrap = 50; //Sets word wrapping on the body of the message to a given number of characters
138 $mail->IsHTML(true); //Sets message type to HTML
139 $mail->Subject = 'Email Verification'; //Sets the Subject of the message
140 $mail->Body = $mail_body; //An HTML or plain text message body
141 if($mail->Send()) //Send an Email. Return true on success or false on error
142 {
143 $message = '<label class="text-success">Register Done, Please check your mail.</label>';
144 }
145 }
146 }
147}
148
149?>
150<div class="fusion-page-title-bar fusion-page-title-bar-breadcrumbs fusion-page-title-bar-left">
151 <div class="fusion-page-title-row">
152 <div class="fusion-page-title-wrapper">
153 <div class="fusion-page-title-captions">
154 <h1 class="entry-title"><?php echo 'Chiab_Gigi / ' .$title ?></h1>
155 </div>
156 <div class="fusion-page-title-secondary">
157 <div class="fusion-breadcrumbs">
158 <span><?php echo $title ?></span>
159 <span class="fusion-breadcrumb-sep">/</span>
160 <a href="../../index.php">Home</a>
161 <span class="fusion-breadcrumb-sep">/</span>
162 <a href="../../contact_email.php">Contact</a>
163 <span class="fusion-breadcrumb-sep">/</span>
164 <a href="../../application/views/logout.php">*</a>
165 <!-- <span class="fusion-breadcrumb-sep">/</span>
166 <a href="#"> </a> -->
167 </div>
168 </div>
169 </div>
170 </div>
171</div>
172<!--==============================
173 Body
174=================================-->
175
176<div class="container" style="width:100%; max-width:600px">
177 <div class="col-sm-12">
178 <p><img src="../../assets/images/blank.png" alt=""></p>
179 </div>
180 <div class="panel panel-default">
181 <div class="panel-heading"><h4>Register</h4></div>
182 <div class="panel-body">
183 <form method="post" id="register_form">
184 <?php echo $message; ?>
185
186 <div class="form-group md-form md-outline">
187 <input type="hidden" name="role_id" class="form-control" value="4" required />
188 </div>
189
190 <div class="form-group md-form md-outline">
191 <label for="first_name">First Name</label>
192 <input type="text" name="first_name" id="first_name" class="form-control" pattern="[a-zA-Z ]+" required />
193 </div>
194
195 <div class="form-group md-form md-outline">
196 <label for="last_name">Last Name</label>
197 <input type="text" name="last_name" id="last_name" class="form-control" pattern="[a-zA-Z ]+" required />
198 </div>
199
200 <div class="form-group md-form md-outline">
201 <label for="user_name">User Name</label>
202 <input type="text" name="user_name" id="user_name" class="form-control" pattern="[a-zA-Z ]+" required />
203 </div>
204
205 <div class="form-group md-form md-outline">
206 <label for="user_email">User Email</label>
207 <input type="email" name="user_email" id="user_email" class="form-control" pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" required />
208 </div>
209
210 <div class="form-group md-form md-outline"><!-- id="show_hide_password" -->
211 <label for="user_password">Password</label>
212 <input type="password" name="user_password" id="user_password" class="form-control" data-toggle="user_password" required />
213 <span toggle="#user_password" class="fa fa-fw fa-eye field-icon toggle-password"></span>
214 </div>
215
216 <!-- <div class="form-group">
217 <label for="browse">Choose Image</label>
218 <input id="browse" name="uPic" type="file" accept="image/*" />
219 <div id="preview"></div>
220 </div>-->
221
222 <div class="form-group">
223 <label for="">Profile Img.</label>
224 <input class="input-group" type="file" name="uPic" id="uPic" accept="image/*" />
225 </div>
226
227
228 <div class="form-group">
229 <input type="submit" name="register" id="register" value="Register" class="btn btn-info" />
230 </div>
231 </form>
232 <p align="right"><a href="login.php">Login</a></p>
233 </div>
234 </div>
235 <div class="col-sm-12">
236 <p><img src="../../assets/images/blank.png" alt=""></p>
237 </div>
238
239 <?php
240 echo '<pre>'; // Array |
241 print_r($_FILES); // ( | di conseguenza è vuoto
242 echo '</pre>'; // ) |
243
244 ?>
245
246</div>
247<?php include ('footer.php'); ?>