Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,34 @@
`#php` `#server` `#master-in-software-development`
`#php` `#basics` `#master-in-software-development`

# PHP Server Environment <!-- omit in toc -->

<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0-blue.svg?cacheSeconds=2592000" />
</p>


> In this project you will learn how to explore the content of the variable $_SERVER which is injected to the running script, in it we can find information about the server environment and the client.
# PHP Server Environment <!-- omit in toc -->

## Index <!-- omit in toc -->
> In this project I learned how to do a login page with authentication and a private page for logged users.

- [Requirements](#requirements)
- [Repository](#repository)
- [Technologies used](#technologies-used)
- [Project delivery](#project-delivery)
- [Resources](#resources)
All the exercises have been done using PHP as language and using Xampp as web server.

## What I've learned

## Requirements

- Learn how to use the $_SERVER
- Understand what a server-side language is and what it is used for
- Learn how to do a basic login page with PHP.

## Repository
- What is a global variable.

First of all you must fork this project into your GitHub account.
- How to use the sessions in PHP.

To create a fork on GitHub is as easy as clicking the “fork” button on the repository page.
- How to store data that are entered by the user.

<img src="https://docs.github.com/assets/cb-23088/images/help/repository/fork_button.png" alt="Fork on GitHub" width='450'>

## Technologies used

\* PHP

## Project delivery


To deliver this project you must send a Pull Request as explained in the Students Handbook. Remember that the PR title must be with the format
- Solution: + NAME AND SURNAME or TEAM NAMES AND SURNAMES.
- For example: "Solution: Josep Riera", "Solution: Josep Riera, Toni Suárez, Marta Vázquez"
\* PHP

## Resources
\* CSS

- [$_SERVER](https://www.php.net/manual/en/reserved.variables.server.php)
- [PHP.ini](https://www.php.net/manual/es/configuration.file.php)
- [PHP Superglobals](https://code.tutsplus.com/es/tutorials/php-superglobals-explained-with-cheatsheet--cms-36598)
## Autor
* **[David Moina](https://github.com/davidmoina)**
12 changes: 12 additions & 0 deletions close_session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
session_start();
session_destroy();

unset($_SESSION["username"]);
unset($_SESSION["user_password"]);

unset($_POST["username"]);
unset($_POST["user_password"]);

header("Location: index.php");
?>
3 changes: 3 additions & 0 deletions exercises/phpinfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
phpinfo();
?>
5 changes: 5 additions & 0 deletions exercises/server_variables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
echo "<pre>";
print_r($_SERVER);
echo "</pre>";
?>
10 changes: 10 additions & 0 deletions exercises/session_variables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
session_start();

$_SESSION['browser'] = $_SERVER['HTTP_USER_AGENT'];
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['time'] = time();
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
?>
Binary file added images/profile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/profile2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
session_start();

if(isset($_SESSION["username"]) && isset($_SESSION["user_password"])) {
header("Location: panel.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://kit.fontawesome.com/8bbf7b9ae4.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style.css">
<title>Login</title>
</head>
<body>
<main class="main">
<form class="form card" method="post" action="validate.php">
<div class="card_header">
<svg height="24" width="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M4 15h2v5h12V4H6v5H4V3a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v18a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-6zm6-4V8l5 4-5 4v-3H2v-2h8z" fill="currentColor"></path>
</svg>
<h1 class="form_heading">Sign in</h1>
</div>
<div class="field">
<label for="username">Username</label>
<input id="username" placeholder="Username" type="text" name="username" class="input">
</div>

<div class="field">
<label for="password">Password</label>
<input id="password" placeholder="Password" type="password" name="user_password" class="input">
</div>
<div class="field field-button">
<button type="submit" class="button">Login</button>
</div>
</form>
<?php
if(isset($_GET["error"])) {
if($_GET["error"] == "incorrect_data") {
echo "<p class='error1'><i class='fa-solid fa-triangle-exclamation'></i> Username or password wrong.</p>";
} else {
echo "<p class='error1'><i class='fa-solid fa-triangle-exclamation'></i> Please login first</p>";
}
}
?>
</main>
</body>
</html>
52 changes: 52 additions & 0 deletions panel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
session_start();
if(!isset($_SESSION["username"]) && !isset($_SESSION["user_password"])) {
header("location: index.php?error=private_zone");
}

$username = $_SESSION["username"];

function image() {
if($_SESSION["username"] == "luis") {
echo "./images/profile2.jpg";
return;
}
echo "./images/profile.jpg";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<script src="https://kit.fontawesome.com/8bbf7b9ae4.js" crossorigin="anonymous"></script>
<title>Profile</title>
</head>
<body>
<header>
<h2 class="title">Profile</h2>
<a href="close_session.php"><button type="button">log out</button></a>
</header>
<main>
<section class="container">
<div class="profile-box">
<img class="profile-pic" src=<?=image()?> width="200px" alt="profile img">
<h3><?=$username?></h3>
<p>Student at Assembler Institute</p>
<div class="social-media">
<i class="fa-brands fa-instagram"></i>
<i class="fa-brands fa-linkedin"></i>
<i class="fa-brands fa-github"></i>
</div>
<button>Edit profile</button>
<div class="profile-bottom">
<p>See more</p>
<i class="fa-solid fa-arrow-down"></i>
</div>
</div>
</section>
</main>
</body>
</html>
Loading