Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
sopham
/
todolist
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
142cce75
authored
May 13, 2019
by
sopham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comment, delete unnescessary code
parent
53c6c4d7
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
138 additions
and
14 deletions
authentication.php
avatar-display.php
delete-all.php
delete-complete.php
display.php
function.js
index.php
insert.php
login_page.php → login_page.html
logout.php
upload.php
authentication.php
View file @
142cce75
<?php
session_start
();
//include the database connection data
require_once
"dbconnection.php"
;
//make the query
if
(
$stmt
=
$link
->
prepare
(
'SELECT ID,password FROM users WHERE username= ?'
))
{
//bind user input to query
$stmt
->
bind_param
(
's'
,
$_POST
[
'username'
]);
//execute query
$stmt
->
execute
();
//transfer a result set from last query
$stmt
->
store_result
();
if
(
$stmt
->
num_rows
>
0
)
{
//bind variables to a prepared statement for result storage
$stmt
->
bind_result
(
$id
,
$password
);
//fetch results from the prepared statement to bound variables
$stmt
->
fetch
();
//if password is correct, establish session
if
(
$_POST
[
'password'
]
===
$password
)
{
session_regenerate_id
();
$_SESSION
[
'loggedin'
]
=
TRUE
;
...
...
@@ -19,6 +35,11 @@ if ($stmt = $link->prepare('SELECT ID,password FROM users WHERE username= ?')) {
echo
"Incorrect password"
;
}
}
//close the statement
$stmt
->
close
();
}
//close the connection
$link
->
close
();
?>
avatar-display.php
0 → 100644
View file @
142cce75
<?php
session_start
();
//include database connection data
include_once
"dbconnection.php"
;
//make the query
$query
=
"SELECT image FROM users WHERE username=?"
;
//prepare the query with empty values as placeholder
$query
=
$link
->
prepare
(
$query
);
//bind value to the prepared query
$query
->
bind_param
(
's'
,
$_SESSION
[
'name'
]);
//execute the query
$query
->
execute
();
//bind variable to the prepared query
$query
->
bind_result
(
$location
);
//fetch the result to variable
$query
->
fetch
();
//return the location folder as response
echo
$location
;
//close the statement
$query
->
close
();
//close the connection
$link
->
close
();
?>
delete-all.php
View file @
142cce75
<?php
//include database connection data
include_once
"dbconnection.php"
;
//make a query
$query
=
"TRUNCATE TABLE toDoList;"
;
//perform the query on the database
$result
=
$link
->
query
(
$query
);
//check if there is any task deleted
if
(
$result
->
num_rows
<=
0
)
{
echo
"No task was deleted"
;
}
//close the connection
$link
->
close
();
?>
delete-complete.php
View file @
142cce75
<?php
//include database connection data
include_once
"dbconnection.php"
;
//make the query
$query
=
"DELETE FROM toDoList WHERE ID=?"
;
//prepare empty values as placeholders
$query
=
$link
->
prepare
(
$query
);
//bind variable to the prepared query
$query
->
bind_param
(
's'
,
$_GET
[
'id'
]);
//execute the query
$query
->
execute
();
//close the statement
$query
->
close
();
//close the connection
$link
->
close
();
?>
display.php
View file @
142cce75
<?php
header
(
'Content-type: application/json'
);
//include database connection data
include_once
"dbconnection.php"
;
//make the query
$query
=
"SELECT ID,task FROM toDoList;"
;
$result
=
$link
->
query
(
$query
);
//error handling
if
(
!
$result
)
die
(
"Database access failed"
);
//define an array to store query results
$data
=
array
();
//store id and task as key, value
for
(
$i
=
0
;
$i
<
$result
->
num_rows
;
++
$i
)
{
//$task = array();
$row
=
$result
->
fetch_array
(
MYSQLI_NUM
);
$data
[
$row
[
0
]]
=
$row
[
1
];
}
//return json data
header
(
'Content-Type: application/json'
);
echo
json_encode
(
$data
);
//close the connection
$link
->
close
();
?>
function.js
View file @
142cce75
index.php
View file @
142cce75
<?php
session_start
();
//if the user is not logged in, redirect to login page
//if the user is not logged in,
delete the session cookie,
redirect to login page
if
(
!
isset
(
$_SESSION
[
'loggedin'
]))
{
session_destroy
();
//delete the session cookie
$params
=
session_get_cookie_params
();
setcookie
(
session_name
(),
''
,
0
,
$params
[
'path'
],
$params
[
'domain'
],
$params
[
'secure'
],
isset
(
$params
[
'httponly'
]));
header
(
'Location: login_page.php'
);
exit
();
//redirect to the login page
header
(
'Location: login_page.html'
);
}
?>
<!DOCTYPE html>
...
...
insert.php
View file @
142cce75
<?php
session_start
();
//include database connection data
include_once
"dbconnection.php"
;
//$query = "INSERT INTO toDoList (task) VALUES (?) ";
$query1
=
"INSERT INTO toDoList (task, userID) VALUES (?,?) "
;
$query1
=
$link
->
prepare
(
$query1
);
$query1
->
bind_param
(
'si'
,
$_POST
[
'task'
],
$_SESSION
[
'id'
]);
//$query -> bind_param('si', $_POST['task']);
$query1
->
execute
();
//make the query
$query
=
"INSERT INTO toDoList (task, userID) VALUES (?,?) "
;
//prepare empty values as placeholders
$query
=
$link
->
prepare
(
$query1
);
//bind variables to the prepared query
$query
->
bind_param
(
'si'
,
$_POST
[
'task'
],
$_SESSION
[
'id'
]);
//execute the query
$query
->
execute
();
//return the last id task as response
$last_id
=
mysqli_insert_id
(
$link
);
echo
$last_id
;
$query1
->
close
();
//close the statement
$query
->
close
();
//close the connection
$link
->
close
();
?>
login_page.
php
→
login_page.
html
View file @
142cce75
File moved
logout.php
View file @
142cce75
<?php
session_start
();
//unset all the session variables
session_unset
();
//destroy session
session_destroy
();
//delete the session cookie
$params
=
session_get_cookie_params
();
setcookie
(
session_name
(),
''
,
0
,
$params
[
'path'
],
$params
[
'domain'
],
$params
[
'secure'
],
isset
(
$params
[
'httponly'
]));
header
(
"Location: login_page.php"
);
//redirect to login page
header
(
"Location: login_page.html"
);
?>
upload.php
View file @
142cce75
<?php
session_start
();
//include database connection data
include_once
'dbconnection.php'
;
//check if the image is uploaded
if
(
is_uploaded_file
(
$_FILES
[
'file'
][
'tmp_name'
]))
{
//save source and target to variables
$sourcePath
=
$_FILES
[
'file'
][
'tmp_name'
];
$targetPath
=
"upload/"
.
basename
(
$_SESSION
[
'name'
]
.
'.'
.
end
((
explode
(
"."
,
$_FILES
[
'file'
][
'name'
]))));
//move uploaded file to target folder
if
(
move_uploaded_file
(
$sourcePath
,
$targetPath
))
{
//set session variable to the image location
$_SESSION
[
'avatar'
]
=
$targetPath
;
//make a query to update database with image location
$query
=
"UPDATE users SET image=? WHERE username=?"
;
//prepare empty values as placeholders
$query
=
$link
->
prepare
(
$query
);
//bind variables to the prepared query
$query
->
bind_param
(
'ss'
,
$targetPath
,
$_SESSION
[
'name'
]);
//execute the query
$query
->
execute
();
//close the prepared statement
$query
->
close
();
//close the connection
$link
->
close
();
//return the image location as the response
echo
$targetPath
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment