Hey guys, Berk here.
Today I'll be showing my latest project, Habbo Archive. I know that I still suck on PHP but I'm still learning so who cares!
So about name, I know I could find a better name but, I can't as I'm not creative.
So my aim on this project is, making myself more experienced and having some fun.
This has no github at the moment, I might do soon as soon as I learn how to use git.
Code snippets:
Login: (Uses AJAX)
JS:
PHP:
JS:
Code:
$('#btn-login').click(function() {
var username = $('#login-username').val();
var password = $('#login-password').val();
new PNotify({
title: 'Processing...',
text: 'Logging you in...',
type: 'info'
});
$.ajax({
url : 'system/js/login.php',
method: 'POST',
data: {
username: username,
password: password
}
}).done(function(res) {
new PNotify({
title : 'Success!',
text: 'Logged in! Redirecting in a moment...',
type:'success'
});
setTimeout(function() {
window.location.href = 'index.php';
}, 2000);
}).fail(function(err) {
switch (err) {
case 'username':
return new PNotify({
title: 'Invalid credentials!',
text: "User doesn't exist!",
type: 'error'
});
case 'password':
return new PNotify({
title: 'Invalid credentials!',
text: 'Password is incorrect!',
type: 'error'
});
default:
return new PNotify({
title: 'Error Occurred',
text: 'An error occurred! Please contact the webmaster.',
type: 'error'
});
}
});
});
PHP:
<?php
if (isset($_POST['username']) && isset($_POST['password'])) {
include('../config.php');
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $db->prepare('SELECT `password` FROM `users` WHERE `username` = :u');
$stmt->bindParam(':u', $username, PDO::PARAM_STR);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$db_password = $stmt->fetchColumn();
if (password_verify($password, $db_password)) {
$_SESSION['harchive_login'] = true;
$_SESSION['login'] = true;
$_SESSION['username'] = $username;
exit('success');
} else {
http_response_code(401);
exit('password');
}
} else {
http_response_code(401);
exit('username');
}
} else {
http_response_code(403);
exit('error here that doesnt really matter');
}
Index (Not Logged in):
Index (Logged in, have staff abitlities):
Log in & Register:
Login in action:
Index (Logged in, have staff abitlities):
Log in & Register:
Login in action:
You must be registered for see links
So thats it for today, as soon as I do more things I'll get you guys notified.
Last edited: