lec-php-06
<?php
if ($_SERVER['REQUEST_METHOD'] === "GET") {
if (isset($_COOKIE['first-name']) && $_COOKIE['first-name'] !== "n/a") {
$msg = "Welcome back, {$_COOKIE['first-name']}!";
} else {
$msg = "Hi there!";
setcookie('first-name', 'n/a');
}
}
require 'hello.view.php';A user goes to hello.php for the first time.
<body>
<h1><?= $msg ?></h1>
</body>hello.php
hello.view.php
<?php
if ($_SERVER['REQUEST_METHOD'] === "GET") {
if (isset($_COOKIE['first-name']) && $_COOKIE['first-name'] !== "n/a") {
$msg = "Welcome back, {$_COOKIE['first-name']}!";
} else {
$msg = "Hi there!";
setcookie('first-name', 'n/a');
}
}
require 'hello.view.php';A user comes BACK to hello.php.
<body>
<h1><?= $msg ?></h1>
</body>hello.php
hello.view.php
<?php
session_start();
$_SESSION['user'] = $_GET['user'] ?? 'unknown';
if ($_SESSION['user'] === "betty") {
header("Location: here.php");
} else {
header("Location: there.php");
}
exit();landing.php
A user goes to landing.php?user=bobby for the first time.
What 3 arrays did we have again?
Next week, we'll actually start writing DB code...just in time for Milestone 4 folks to use it the week after.
◉ We're gonna make rabbits. How exciting!
◉ Wait...my Codespace has a database server on it?!?
◉ How do I connect to that server?
◉ How do I create a database, tables, and data on the server?
◉ How do I add/delete/modify data from tables?
Brought to you by Rabbit.
This course has 3 prerequisites, right?
Does this mean you have to remember all the things from all these courses?!?!
Hell, no.
That's it. Breeeeeeathe.
Create an Order class into lab-02!
The price calculation can be moved into the class.
And the price-per-can would make a wonderful static property.
Of course you do!
Nope. But go ahead if you want to.
See?
Click this...
...to show this.
Click it!
Click this...
Put a reasonable name in here.
This should be 'mariadb'.
Choose MariaDB.
Your gateway to database wonder.
We can do this sort of thing manually...but I'd rather use a script!
Click this...
...which opens this.
Script results show up here. Green is good. Red, not so much.
Click on the refresh icon.
Sweet!
I'd just get in here a play around. It's pretty intuitive, tbh.
The docs are at https://database-client.com/#/document