-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8ab1fd
commit ce262df
Showing
4 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
session_start(); // Start the session | ||
|
||
if (!isset($_SESSION['username'])) { | ||
// Redirect users who are not logged in to the login page | ||
header("Location: login.php"); | ||
exit(); | ||
} | ||
|
||
$songsDirectory = 'songs/'; | ||
$songs = scandir($songsDirectory); | ||
shuffle($songs); | ||
?> | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Music Player</title> | ||
<link rel="stylesheet" href="css/style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h2>Welcome, <?php echo $_SESSION['username']; ?></h2> | ||
<h3>Your Music Collection</h3> | ||
<div id="audio-container"> | ||
<h3 id="current-song-title">No song selected</h3> | ||
<audio id="audio-player" controls> | ||
<source src="" type="audio/mpeg"> | ||
Your browser does not support the audio element. | ||
</audio> | ||
</div> | ||
<div id="controls-container"> | ||
<button id="shuffle-button">Shuffle</button> | ||
<button id="previous-button">Previous</button> | ||
<button id="next-button">Next</button> | ||
</div> | ||
<div class="search"> | ||
<input type="text" id="search-input" placeholder="Search songs..."> | ||
<button onclick="search-button">Search</button> | ||
</div> | ||
<ul id="song-list"> | ||
<?php | ||
foreach ($songs as $song) { | ||
if ($song !== '.' && $song !== '..') { | ||
$songPath = $songsDirectory . $song; // Full path to the song | ||
echo '<li><a href="' . $songPath . '" onclick="playSong(\'' . $songPath . '\', \'' . $song . '\'); return false;" data-song-url="' . $songPath . '" data-song-title="' . $song . '">' . $song . '</a></li>'; | ||
} | ||
} | ||
?> | ||
</ul> | ||
|
||
<h3>Your Favorites</h3> | ||
<ul id="favorites-list"> | ||
<!-- Display favorites here --> | ||
</ul> | ||
<p><a href="logout.php">Logout</a></p> | ||
</div> | ||
<script src="js/script.js"></script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
session_start(); | ||
|
||
if (isset($_SESSION['username'])) { | ||
// Redirect logged-in users to the main page | ||
header("Location: index.php"); | ||
exit(); | ||
} | ||
?> | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Login</title> | ||
<link rel="stylesheet" href="css/style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h2>Login</h2> | ||
<?php | ||
if (isset($_SESSION['error'])) { | ||
echo '<p class="error">' . $_SESSION['error'] . '</p>'; | ||
unset($_SESSION['error']); | ||
} | ||
?> | ||
<form action="login_process.php" method="POST"> | ||
<input type="text" name="username" placeholder="Username" required> | ||
<input type="password" name="password" placeholder="Password" required> | ||
<button type="submit">Login</button> | ||
</form> | ||
<p>Don't have an account? <a href="register.php">Register</a></p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
session_start(); | ||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | ||
$username = $_POST['username']; | ||
$password = $_POST['password']; | ||
|
||
// Read user data from the users.txt file | ||
$userData = file_get_contents('users/users.txt'); | ||
$userData = explode("\n", $userData); | ||
|
||
foreach ($userData as $user) { | ||
list($savedUsername, $savedHashedPassword) = explode(':', $user); | ||
if ($username === $savedUsername && password_verify($password, $savedHashedPassword)) { | ||
$_SESSION['username'] = $username; | ||
header("Location: index.php"); // Redirect to the main page after successful login | ||
exit(); | ||
} | ||
} | ||
|
||
$_SESSION['error'] = "Invalid username or password"; | ||
header("Location: login.php"); // Redirect back to the login page with an error message | ||
exit(); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
session_start(); | ||
|
||
if (isset($_SESSION['username'])) { | ||
// Redirect logged-in users to the main page | ||
header("Location: index.php"); | ||
exit(); | ||
} | ||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') { | ||
$username = $_POST['username']; | ||
$password = $_POST['password']; | ||
$confirm_password = $_POST['confirm_password']; | ||
|
||
if ($password !== $confirm_password) { | ||
$_SESSION['error'] = "Passwords do not match."; | ||
} else { | ||
// Hash the password before saving it | ||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT); | ||
|
||
// Save the username and hashed password to a 'users.txt' file | ||
$userData = "$username:$hashedPassword\n"; // Format: username:hashed_password | ||
file_put_contents('users/users.txt', $userData, FILE_APPEND | LOCK_EX); | ||
|
||
// Redirect to the login page after successful registration | ||
$_SESSION['success'] = "Registration successful. You can now login."; | ||
header("Location: login.php"); | ||
exit(); | ||
} | ||
} | ||
?> | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Register</title> | ||
<link rel="stylesheet" href="css/style.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h2>Register</h2> | ||
<?php | ||
if (isset($_SESSION['error'])) { | ||
echo '<p class="error">' . $_SESSION['error'] . '</p>'; | ||
unset($_SESSION['error']); | ||
} | ||
?> | ||
<form action="" method="POST"> | ||
<input type="text" name="username" placeholder="Username" required> | ||
<input type="password" name="password" placeholder="Password" required> | ||
<input type="password" name="confirm_password" placeholder="Confirm Password" required> | ||
<button type="submit">Register</button> | ||
</form> | ||
<p>Already have an account? <a href="login.php">Login</a></p> | ||
</div> | ||
</body> | ||
</html> | ||
|