PHP Classes

File: php/reg.php

Recommend this page to a friend!
  Classes of Ann   Purp Project   php/reg.php   Download  
File: php/reg.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Purp Project
Application to manage photo albums
Author: By
Last change: Update of php/reg.php
Date: 1 year ago
Size: 3,998 bytes
 

Contents

Class file image Download
<?php
    header
("Content-type: application/json");
     
session_start();
    require_once
'includes/connect-db.php';

   
$resp="";
   
$login = $_POST['login'];
   
$age = $_POST['age'];
   
$email = $_POST['email'];
   
$gender = $_POST['gender'];
   
$salt = mt_rand(1, 999);
   
$password = $_POST['password'];
   
$check_password = $_POST['check_password'];
   
$avatar = $_POST['avatar'];

   
$error_fields = [];
    if (
$login === '') {
       
$error_fields[] = "login";
    }
    if (
$password === '') {
       
$error_fields[] = "password";
    }
    if (
$email === '') {
       
$error_fields[] = "email";
    }
    if (
$check_password === '') {
       
$error_fields[] = "check_password";
    }
    if (!empty(
$error_fields)) {
       
$resp ="????????? ?????? ????";


    } else{
       
$query = "SELECT * FROM `user` WHERE `login`='$login'";
   
$check_login = mysqli_query($connect, $query);
   
$pat = "/^([a-z0-9_-]+\.)*[a-z0-9_-]+@[a-z0-9_-]+(\.[a-z0-9_-]+)*\.[a-z]{2,6}$/";
   
//$pattern = "/\^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}\$/";
   
   
   
if (mysqli_num_rows($check_login) > 0) {
       
$resp = "????? ????? ??? ??????????";
        }else{
            if(
preg_match($pat, $email)){
                if(
strlen($password)< 3){
               
$resp ="?????? ?????? ????????? ?? ????? 3 ????????";
            }else{
                 if (
$password === $check_password) {

   
                   
$password = md5(md5($password) . $salt);
                    
mysqli_query($connect, "INSERT INTO `user` (`id`, `login`, `age`, `email`, `gender`, `password`, `salt`, `photo`) VALUES (NULL, '$login', '$age', '$email', '$gender', '$password', '$salt', 'account.png')");
   
                   
$resp ="??????????? ?????? ???????!";
                }else {
                   
$resp = "?????? ?? ?????????";
      
                }
   
            }
            } else{
               
$resp = "???????????? email";
            }
          
        }
    }
   
  
    echo
json_encode(['message'=> $resp] );








   
// for($i=0; $i<mysqli_num_rows($result); $i++){

    // if($login != mysqli_fetch_array($result)[0]){
    // if($password === $check_password){
   
    // $password = md5(md5($password) . $salt);
      
       

       
   
       
    // $path = '../img/users/'.time().$_FILES['avatar']['name'];
       
    // if(!move_uploaded_file($_FILES['avatar']['tmp_name'], $path)){
    // $_SESSION['message'] = '?????? ??? ???????? ???????????';
    // header('Location: ../register.php');
    // }else{
    // mysqli_query($connect, "INSERT INTO `user` (`id`, `login`, `age`, `email`, `gender`, `password`, `salt`, `photo`) VALUES (NULL, '$login', '$age', '$email', '$gender', '$password', '$salt', '$path')");
    // $_SESSION['message'] = '??????????? ?????? ???????';
    // echo "<script>alert('??????????? ?????? ???????')</script>";
    // header('Location: ../login.php');
    // }

    // }else{
    // $_SESSION['message'] = '?????? ?? ?????????';
    // header('Location: ../register.php');
    // }
    // }
    // else{
    // $_SESSION['message'] = '???????????? ? ????? ??????? ??? ??????????!';
    // header('Location: ../register.php');
    // }

    // }

   
?>