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
39 changes: 12 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,30 @@
`#php` `#server` `#master-in-software-development`
# PHP Server Environment 💻<!-- omit in toc -->

# PHP Server Environment <!-- omit in toc -->
> In this project we learnt 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 as well as creating a simple login form that validates the inputs, throws alerts for different cases and that can logout successfully.
For this I used session_start() to maintain the variables as well as: unset($_SESSION), session_destroy() and session_write_close() to logout.

<p>
<img alt="Version" src="https://img.shields.io/badge/version-1.0-blue.svg?cacheSeconds=2592000" />
</p>
I also used Bootstrap to create a simple and beautiful layout and desing.

> 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.

## Index <!-- omit in toc -->
## Index ☟<!-- omit in toc -->

- [Requirements](#requirements)
- [Repository](#repository)
- [Technologies used](#technologies-used)
- [Project delivery](#project-delivery)
- [Resources](#resources)

## Requirements
## Requirements

- Learn how to use the $_SERVER
- Understand what a server-side language is and what it is used for
- Learn how to handle errors
- Learn how to use Sessions

## Repository

First of all you must fork this project into your GitHub account.

To create a fork on GitHub is as easy as clicking the “fork” button on the repository page.

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

## Technologies used
## Technologies used

\* PHP
\* XAMPP
\* Bootstrap

## 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"

## Resources
## Resources 👀

- [$_SERVER](https://www.php.net/manual/en/reserved.variables.server.php)
- [PHP.ini](https://www.php.net/manual/es/configuration.file.php)
Expand Down
10 changes: 10 additions & 0 deletions loginExercise/close_session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

session_start();
unset($_SESSION);
session_destroy();
session_write_close();
header('Location: index.php?logout=success');
die;

?>
93 changes: 93 additions & 0 deletions loginExercise/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html lang="en">

<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<script defer src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script defer src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
</head>

<body>
<?php
// $email = $_POST['email'];
// $name = $_POST['user'];
// $password = $_POST['password'];

// if(isset($_POST['submit'])) {
// // Check if email has been entered and is valid
// if(empty($_POST['email'])) {
// $errEmail = 'Please enter a valid email address';
// }
// // check if a password has been entered and if it is a valid password
// else if(empty($_POST['password']) || (preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["password"]) === 0)) {
// $errPass = '<p class="errText">Password must be at least 8 characters and must contain at least one lower case letter, one upper case letter and one digit</p>';
// } else {
// echo "The form has been submitted";
// }
// }
?>
<div class="container-md align-content-center">

<h1>Log In</h1>


<?php
if (isset($_GET["logout"])){
if($_GET["logout"] === "success"){
echo "<div class='alert alert-primary' role='alert'>Logged out successfully.</div>";
}
}
?>

<?php
if(isset($_GET["error"])){
switch ($_GET["error"]){
case "incorrect":
?>
<div class='alert alert-primary' role='alert'>Your Email or Password are incorrect.</div>
<?php
break;
case "userempty":
?><div class='alert alert-primary' role='alert'>Your Email is empty.</div>
<?php
break;
case "passempty":
?><div class='alert alert-primary' role='alert'>Your Password is empty.</div>
<?php
break;
case "bothempty":
?><div class='alert alert-primary' role='alert'>Both inputs are empty.</div>
<?php
break;
}
}
?>

<form role="form" method="post" action="validate.php">
<div class="form-floating mb-3">
<label for="inputEmail" class="col-sm-2 col-form-label">Email</label>
<input type="email" class="form-control" id="inputEmail" name="email" placeholder="name@example.com">
</div>

<div class="form-floating mb-3">
<label for="inputPassword3" class="col-sm-2 col-form-label">Password</label>
<input type="password" class="form-control" id="inputPassword" name="password" placeholder="Password">
</div>

<div class="form-group row">
<input type="submit" value="Sign in" name="submit" class="btn btn-primary" />
</div>
</form>
</div>
</body>

</html>
29 changes: 29 additions & 0 deletions loginExercise/panel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!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="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<script defer src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script defer src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<title>PRIVATE ZONE</title>
</head>
<body>
<div class="container-md align-content-center">

<h1>PRIVATE ZONE</h1>
<a class="btn btn-primary" href="close_session.php" role="button">Logout</a>

</div>

</body>
</html>
20 changes: 20 additions & 0 deletions loginExercise/validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

session_start();

$user = "ruben@ruben.com";
$pass = "1234";

if ($user===$_REQUEST["email"] && $pass===$_REQUEST["password"]){
header("Location: panel.php");
} else if ($_REQUEST["password"] === "" && $_REQUEST["email"] === "") {
header("Location: index.php?error=bothempty");
} else if ($_REQUEST["email"] === "") {
header("Location: index.php?error=userempty");
} else if ($_REQUEST["password"] === "") {
header("Location: index.php?error=passempty");
} else {
header("Location: index.php?error=incorrect");
}

?>
9 changes: 9 additions & 0 deletions server_variables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

echo "<pre>";

print_r($_SERVER);

echo "</pre>";

?>
13 changes: 13 additions & 0 deletions session_variables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

session_start();

$_SESSION['browser'] = $_SERVER['HTTP_USER_AGENT'];
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['time'] = time();

echo "<pre>";
print_r($_SESSION);
echo "</pre>";

?>