This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
executable file
·84 lines (78 loc) · 2.24 KB
/
functions.php
File metadata and controls
executable file
·84 lines (78 loc) · 2.24 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
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
<?php
session_start();
function connect_db(){
/*
mysqli connect function
*/
GLOBAL $connect;
$connect = mysqli_connect("localhost","admin","iamnotadmin","hot-chat"); // host, username, password, DataBase
}
connect_db();
function getChats($user){
GLOBAL $connect;
$sql="SELECT * FROM `chat` WHERE usersend= '$user' OR usergive='$user' ORDER by `id` ASC ";
$res=mysqli_query($connect,$sql);
return $res;
}
function getPicture($id){
/*
get your id for show your picture
*/
GLOBAL $connect;
$sql="SELECT * FROM `users` WHERE id = '$id' ORDER by `id` DESC ";
$res=mysqli_query($connect,$sql);
return $res;
}
function getOtherPicture($user){
/*
get other users username for show their picture
*/
GLOBAL $connect;
$sql="SELECT * FROM `users` WHERE username = '$user' ORDER by `id` DESC ";
$res=mysqli_query($connect,$sql);
return $res;
}
function uploadPicture($id,$pre){
/*
get your id and a pre for create name to save picture in DataBase
*/
GLOBAL $connect;
$pic=$_FILES["pic"];
if(is_uploaded_file($pic["tmp_name"])){ // check picture type
$dst="pic/";
if($pic["type"]=="image/jpg"){
$type="jpg";
}else if($pic["type"]=="image/png"){
$type="png";
}else if($pic["type"]=="image/jpeg"){
$type="jpeg";
}
$picname="pic".$pre.$id.$type;
move_uploaded_file($pic["tmp_name"],$dst.$picname);
}
$sql="UPDATE `users` SET `pic`='$picname' WHERE id='$id'";
$res=mysqli_query($connect,$sql);
header("location:main.php?er=uploaded!");
}
// TODO clean codes please
// TODO create email Authentication
// TODO create Encryption function
// TODO solve logical bug on Authentication for main page
/*
function checkSession($user,$pass)
{
$username = $_SESSION["username"];
$password = $_SESSION["password"];
$sql ="SELECT * FROM `users` where username='$username' and password='$password'";
$res = mysqli_query($connect, $sql);
if (mysqli_num_rows($res) > 0 ) {
$row = mysqli_fetch_array($res, 1);
if ($_SESSION["password"] != $row["password"]) {
header("location:index.php?er=refused");
}
} else {
header("location:index.php?er=refused");
}
}
*/
?>