0% found this document useful (0 votes)
26 views4 pages

Web Application 2

The document describes how to build a student login portal with PHP and HTML using Visual Studio Code. It includes creating files for a login page, validating credentials, storing user data in sessions, and redirecting to a dashboard with pages for grades, courses, and assignments.

Uploaded by

Adamu Muhammad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Web Application 2

The document describes how to build a student login portal with PHP and HTML using Visual Studio Code. It includes creating files for a login page, validating credentials, storing user data in sessions, and redirecting to a dashboard with pages for grades, courses, and assignments.

Uploaded by

Adamu Muhammad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Here's an example of a student login portal with pages for grades, courses, and assignments using HTML

and PHP in Visual Studio Code:

1. First, create a new folder for your project in Visual Studio Code and create a new file named
index.php.

2. Add the following code to index.php:

<!DOCTYPE html>

<html>

<head>

<title>Student Login Portal</title>

</head>

<body>

<h1>Student Login Portal</h1>

<form action="login.php" method="post">

<label for="username">Username:</label>

<input type="text" id="username" name="username"><br><br>

<label for="password">Password:</label>

<input type="password" id="password" name="password"><br><br>

<input type="submit" value="Login">

</form>

</body>

</html>

3. Create a new file named login.php.

4. Add the following code to login.php:

<?php

// Start session
session_start();

$username = $_POST['username'];

$password = $_POST['password'];

// Code for validating username and password

if ($valid) {

// Store username in session variable

$_SESSION['username'] = $username;

// Redirect to dashboard page

header("Location: dashboard.php");

exit();

} else {

// Display error message and redirect back to login page

echo "Invalid username or password.";

header("Refresh: 3; url=index.php");

exit();

?>

5. Create a new file named dashboard.php.

6. Add the following code to dashboard.php:


<?php

// Start session

session_start();

// Redirect to login page if username is not set in session variable

if (!isset($_SESSION['username'])) {

header("Location: index.php");

exit();

?>

<!DOCTYPE html>

<html>

<head>

<title>Student Dashboard</title>

</head>

<body>

<h1>Welcome, <?php echo $_SESSION['username']; ?>!</h1>

<ul>

<li><a href="grades.php">Grades</a></li>

<li><a href="courses.php">Courses</a></li>

<li><a href="assignments.php">Assignments</a></li>

<li><a href="logout.php">Logout</a></li>

</ul>

</body>
</html>

In this code, we have created a login page that allows the student to enter their username and
password. When the student clicks the Login button, the form data is sent to login.php.

In login.php, we retrieve the form data using the $_POST superglobal array. We can then validate the
username and password as needed. If the username and password are valid, we store the username in a
session variable and redirect the student to the dashboard page. If the username and password are not
valid, we display an error message and redirect the student back to the login page.

In dashboard.php, we check if the username is set in the session variable. If it is not set, we redirect the
student back to the login page. If it is set, we display the student's username and links to the grades,
courses, and assignments pages.

7. Create a new file named grades.php.

8. Add your grades content to grades.php.

9.Create a new file named courses.php.

10. Add your courses content to `courses

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy