ST Complete Code

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

we follow the following steps:

Step 1: Planning and Designing the Website


Determine the purpose and functionality of the website.
Create a wireframe or sketch to visualize the layout and structure.
Identify the database requirements, such as user information and login credentials.

Step 2: Setting up the Environmen


Install a local server environment like XAMPP or WAMP for development.
Create a project folder to store all website files.

Step 3: Building the Database


Choose a database management system (e.g., MySQL) and create a new database.
Define tables to hold user information, including username and password.

Step 4: Creating the HTML Structure


Write the HTML code to create the basic structure of the website.
Include necessary tags for the header, navigation, content sections, and footer.

Step 5: Styling with CSS


Write the CSS code to style the website according to the desired design.
Use CSS selectors to target specific HTML elements and apply styles.

Step 6: Implementing PHP for Login System


Create a PHP file for the login functionality.
Connect to the database using PHP's MySQL functions or PDO.
Write PHP code to handle user authentication, including validating login credentials and creating
sessions.

Step 7: Implementing Algorithm for Secure Login

Use appropriate hashing algorithms like bcrypt or Argon2 for storing passwords securely.
Apply salting techniques to further enhance password security.

Step 8: Integrating PHP with HTML


Embed PHP code within HTML files to display dynamic content.
Use PHP to fetch user-specific data from the database and display it on relevant pages.

1
Step 9: Testing and Debugging

Test the website's functionality, including user registration, login, and account management.
Debug any issues or errors encountered during testing.

Step 10: Deploying the Website

Choose a hosting provider and register a domain (if necessary).


Upload website files to the hosting server.
Import the database to the server if required.

2
E-commerce electronic website using HTML, CSS, and PHP that incorporates a MySQL
database for a login account system with user-specific content display and registration
functionality.

a registration page (register.html) that allows users to create new accounts,


a login page (index.html) for existing users to login,
a dashboard page (dashboard.php) to display user-specific content, and

Please note that in the code, we can replace


your_username,
your_password, and
your_database_name with your actual database credentials.

HTML code (indexh.html):

<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<form method="post" action="login.php">
<h2>Login</h2>
<label for="username">Username:</label>
<input type="text" name="username" required>
<label for="password">Password:</label>
<input type="password" name="password" required>
<input type="submit" value="Login">
</form>
<p>Don't have an account? <a href="register.html">Register here</a></p>
</div>
</body>
</html>

CSS code (style.css):


.container {
width: 300px;
margin: 0 auto;
padding: 20px;
border: 1px solid #ccc;
}

h2 {
text-align: center;
}

3
label, input {
display: block;
margin-bottom: 10px;
}

input[type="submit"] {
margin-top: 10px;
background-color: #4CAF50;
color: white;
border: none;
padding: 10px;
cursor: pointer;
}

PHP code (login.php):


<?php
session_start();

// Database connection
$host = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";

$conn = mysqli_connect($host, $username, $password, $dbname);


if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// User authentication
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$password = mysqli_real_escape_string($conn, $_POST["password"]);

$sql = "SELECT * FROM users WHERE username='$username'";


$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_assoc($result);
if (password_verify($password, $row["password"])) {
$_SESSION["username"] = $username;
header("Location: dashboard.php");
} else {
echo "Invalid password";
}
} else {
echo "Invalid username";
}
}

mysqli_close($conn);
?>

4
HTML code (register.html):
<!DOCTYPE html>
<html>
<head>
<title>Registration Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<form method="post" action="register.php">
<h2>Register</h2>
<label for="username">Username:</label>
<input type="text" name="username" required>
<label for="password">Password:</label>
<input type="password" name="password" required>
<input type="submit" value="Register">
</form>
</div>
</body>
</html>

PHP code (register.php):


<?php
// Database connection
$host = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database_name";

$conn = mysqli_connect($host, $username, $password, $dbname);


if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

// User registration
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$password = mysqli_real_escape_string($conn, $_POST["password"]);

// Validate input

// Check if username already exists


$sql = "SELECT * FROM users WHERE username='$username'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
echo "Username already exists.";
} else {
// Hash the password
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

// Insert user into database

5
$sql = "INSERT INTO users (username, password) VALUES ('$username',
'$hashedPassword')";
if (mysqli_query($conn, $sql)) {
echo "Registration successful.";
} else {
echo "Error: " . mysqli_error($conn);
}
}
}

mysqli_close($conn);
?>
PHP code (dashboard.php):
<?php
session_start();

// Check if user is logged in


if (!isset($_SESSION["username"])) {
header("Location: index.html");
exit();
}

// Display user-specific content


$username = $_SESSION["username"];
echo "Welcome, $username! This is your dashboard.";

// Additional content and functionality specific to the logged-in user can be added
here

?>

PHP code (logout.php):


<?php
session_start();

// Destroy the session and redirect to login page


session_destroy();
header("Location: index.html");
exit;
?>

You might also like