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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
package-lock.json
50 changes: 12 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,20 @@
`#php` `#server` `#master-in-software-development`
# PHP Environment - MSD OCT22

# PHP Server Environment <!-- omit in toc -->
Project created by [David Pizarro](https://dtpf.es)

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

> 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] 7 or higher.

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

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

## Requirements
## Built With

- Learn how to use the $_SERVER
- Understand what a server-side language is and what it is used for
* [PHP](https://www.php.net/)
* [VSCode](https://code.visualstudio.com/)

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

\* 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"

## Resources

- [$_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)
[PHP]: <https://www.php.net>
89 changes: 89 additions & 0 deletions assets/css/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
body {
background-color: antiquewhite;
}

/*************** index.php ****************/

.form {
display: grid;
place-content: center;
height: 100vh;
justify-content: center;
}

.form-div {
padding: 15px;
border-radius: 5px;
background: rgb(2, 0, 36);
background: radial-gradient(circle, rgb(170, 0, 222) 0%, rgba(82, 9, 121, 0.858061974789916) 35%, rgba(187, 0, 255, 1) 100%);
}

.form .login-info {
margin: 0 auto;
text-align: center;
border: 1px solid black;
height: auto;
max-width: 180px;
margin-top: 15px;
margin-bottom: 20px;
background-color: #fff;
border-radius: 5px;
}

.form .login-info p {
padding: 5px 10px;
margin: 0;
}

/*************** panel.php ****************/

.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
user-select: none;
}

@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}

.b-example-divider {
height: 3rem;
background-color: rgba(0, 0, 0, .1);
border: solid rgba(0, 0, 0, .15);
border-width: 1px 0;
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
}

.b-example-vr {
flex-shrink: 0;
width: 1.5rem;
height: 100vh;
}

.bi {
vertical-align: -.125em;
fill: currentColor;
}

.nav-scroller {
position: relative;
z-index: 2;
height: 2.75rem;
overflow-y: hidden;
}

.nav-scroller .nav {
display: flex;
flex-wrap: nowrap;
padding-bottom: 1rem;
margin-top: -1px;
overflow-x: auto;
text-align: center;
white-space: nowrap;
-webkit-overflow-scrolling: touch;
}
3 changes: 3 additions & 0 deletions close_session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
require_once('methods.php');
closeSession();
14 changes: 14 additions & 0 deletions environment/server_variables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
echo '<pre>';
print_r($_SERVER);
echo '</pre>';

echo '<hr>';

// php.ini search
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
10 changes: 10 additions & 0 deletions environment/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>';
44 changes: 44 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
require_once('methods.php');
autoLogin();
?>

<!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">
<title>Server Environment</title>
<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="./assets/css/index.css">
</head>

<body>
<div class="form">
<div class="form-div">

<div class="login-info">
<p>Email: [email protected]</p>
<p>Password: 12345</p>
</div>

<form action="validate.php" method="POST">
<label for="email" class="form-label text-light">Email</label>
<input type="email" id="email" name="email" placeholder="[email protected]" class="form-control" required>
<br>
<br>
<label for="password" class="form-label text-light">Password</label>
<input type="password" id="password" name="password" class="form-control" required>

<?= ($_SESSION['loginError']) ? "<div class='alert alert-danger mt-4 role='alert'>User or password not valid</div>" : "" ?>
<?= ($_SESSION['userRejected']) ? "<div class='alert alert-danger mt-4 role='alert'>This is a private section</div>" : "" ?>
<input type="submit" value="Login" class="btn btn-dark mt-4 mb-3 w-100">
</form>
</div>
</div>

</body>

</html>
72 changes: 72 additions & 0 deletions methods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
session_start();

function printUser()
{
$email = $_SESSION['email'];
echo "Hello " . $email . "!";
}

function rejectUnidentifiedUser()
{
if (!isset($_SESSION['email'])) {
$_SESSION['loginError'] = false;
$_SESSION['userRejected'] = true;
header('Location: index.php');
exit();
} else {
$_SESSION['userRejected'] = false;
}
}

function autoLogin()
{
if (isset($_SESSION['email'])) {
header('Location: panel.php');
}
}

function setUser()
{
$_email = '[email protected]';
$_password = 12345;

$email = $_POST['email'];
$password = $_POST['password'];

if (isset($_POST['email'])) {
if ($email == $_email && $password == $_password) {
$_SESSION['email'] = $email;
echo $_SESSION['email'];
header('Location: panel.php');
$_SESSION['loginError'] = false;
exit();
} else {
$_SESSION['loginError'] = true;
$_SESSION['userRejected'] = false;
header('Location: index.php');
}
} else {
header('Location: index.php');
}
}

function closeSession()
{
// Remove cookies
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(
session_name(),
'',
time() - 42000,
$params["path"],
$params["domain"],
$params["secure"],
$params["httponly"]
);
}
// Unset and redirect
unset($_SESSION['email']);
header('Location: index.php');
}
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "php-server-environment",
"version": "1.0.0",
"description": "`#php` `#server` `#master-in-software-development`",
"main": "index.php",
"repository": {
"type": "git",
"url": "git+https://github.com/DTPF/php-server-environment.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/DTPF/php-server-environment/issues"
},
"homepage": "https://github.com/DTPF/php-server-environment#readme",
"dependencies": {
"bootstrap": "^5.2.3"
}
}
Loading