-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstarred.php
67 lines (57 loc) · 2.32 KB
/
starred.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Starred File</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="CSS/stylesheet.css" />
<link href="https://fonts.googleapis.com/css?family=Heebo:300" rel="stylesheet">
<link rel="icon" href="LogoIcon.png" type="image/png" sizes="20x20">
</head>
<body>
<div class="back-butt">
<a href="home.php" class="previous round">‹</a>
</div>
<section class="file-load">
<?php
session_start();
$username= $_SESSION['login_user'];
if (isset( $_SESSION['login_user'])){
// Grab user data from the database using the user_id
// Let them access the "logged in only" pages
} else {
// Redirect them to the login page
header("Location: login.php");
exit();
}
if($_SERVER['REQUEST_METHOD']=='POST'){
if (isset($_POST['star'])) {
$value = $_POST['star'];
$path = sprintf("/home/stevenlee/Module2Info/uploads/%s/%s", $username, "star.txt");
$h= fopen($path, "r");
//Boolean to see if username was found
$validator = FALSE;
//Reading File Line-by-Line
while(!feof($h)){
if($value == trim(fgets($h))){
$validator = TRUE;
}
}
//Checking if validator returned true or false to check if username was in txt file.
if($validator== TRUE){
echo "You have UN-starred " .$value;
$content = file_get_contents($path);
$content = str_replace($value, '', $content);
file_put_contents($path, $content);
}
else{
echo "You have starred " .$value;
$text = PHP_EOL . $value;
file_put_contents($path, $text, FILE_APPEND);
}
fclose($h);
}
}
?>
</section>
</body>