Lalaineretardophpsamplecode
Lalaineretardophpsamplecode
BSIT 2 SET A
Sample code of Log In Page using PHP code
//
login_page.php
<?php
if(isset($_POST['submit'])){
$dbHost = "localhost"; //Location Of Database usually its localhost
$dbUser = "xxxx"; //Database User Name
$dbPass = "xxxxxx"; //Database Password
$dbDatabase = "db_name"; //Database Name
/*
The Above code can be in a different file, then you can place include'filename.php'; instead.
*/
//Lets search the databse for the user name and password
//Choose some sort of password encryption, I choose sha256
//Password function (Not In all versions of MySQL).
$usr = mysql_real_escape_string($_POST['username']);
$pas = hash('sha256', mysql_real_escape_string($_POST['password']));
$sql = mysql_query("SELECT * FROM users_table
WHERE username='$usr' AND
password='$pas'
LIMIT 1");
if(mysql_num_rows($sql) == 1){
$row = mysql_fetch_array($sql);
session_start();
$_SESSION['username'] = $row['username'];
$_SESSION['fname'] = $row['first_name'];
$_SESSION['lname'] = $row['last_name'];
$_SESSION['logged'] = TRUE;
header("Location: users_page.php"); // Modify to go to the page you would like
exit;
}else{
header("Location: login_page.php");
exit;
}
}else{ //If the form button wasn't submitted go to the index page, or login page
header("Location: index.php");
exit;
}
?>
users_page.php
<?php
session_start();
if(!$_SESSION['logged']){
header("Location: login_page.php");
exit;
}
echo 'Welcome, '.$_SESSION['username'];
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<style>
body{
font-family: "Lucida Console", "Courier New", monospace;
}
form{
margin: 0px;
border: solid 1px;
border - color : coral;
border-collapse: collapse;
padding: 5px;
text-align: center;
width: 450px;
background-color: light pink;
column-rule-color: yellow;
align-items: center;
color: blue ;
}
h2{
text-align: center;
align-items: center;
background-color: blue;
}
h3{text-align: center;
align-items: center;
background-color: blue;
}
div {
margin: 0px;
border: solid 1px;
border - color : coral;
border-collapse: separate;
padding: 5px;
text-align: left;
width: 450px;
background-color:light pink;
column-rule-color:yellow;
}
</style>
<br><br>
<br><br>
<br><br>
<br><br>
<br><br>
Year Level : <select name="yearTxt" required>
<option value="">Select Year Level</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<br><br>
<br><br>
<br><br>
<input type="checkbox" name="checkBox" required > I hereby certify that the foregoing
information is true and accurate.<br>Are you ready to submit?
<br><br>
</form>
<hr>
<h3>SUMMARY</h3>
<div>
<?php
if (isset($_GET['submitBtn'])) {
?>
<?php
}
?>
</div>
</body>
</html>