trying to keep pace with robyn, on the evening of february 15th
19:23:28 wcarss@vm:~$ php -V
The program 'php' is currently not installed. You can install it by typing:
sudo apt-get install php5-cli
19:23:32 wcarss@vm:~$ sudo apt-get install php5-cli
[sudo] password for wcarss:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
php5-common php5-json php5-readline
Suggested packages:
php-pear php5-user-cache
The following NEW packages will be installed:
php5-cli php5-common php5-json php5-readline
0 upgraded, 4 newly installed, 0 to remove and 479 not upgraded.
Need to get 2,654 kB of archives.
After this operation, 10.5 MB of additional disk space will be used.
Do you want to continue? [Y/n]
[more apt things showing installation]
19:24:09 wcarss@vm:~$ php -v
PHP 5.5.9-1ubuntu4.14 (cli) (built: Oct 28 2015 01:34:46)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
19:24:13 wcarss@vm:~$ php -a
Interactive mode enabled
php > echo "y helo thar\n";
y helo thar
php > ^D19:24:28 wcarss@vm:~$
19:24:34 wcarss@vm:~$ mysql -V
mysql Ver 14.14 Distrib 5.5.41, for debian-linux-gnu (x86_64) using readline 6.3
19:24:36 wcarss@vm:~$ nginx -V
The program 'nginx' can be found in the following packages:
* nginx-core
* nginx-extras
* nginx-full
* nginx-light
* nginx-naxsi
Try: sudo apt-get install <selected package>
19:24:45 wcarss@vm:~$ sudo apt-get install nginx-core
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
nginx-common
Suggested packages:
fcgiwrap nginx-doc
The following NEW packages will be installed:
nginx-common nginx-core
0 upgraded, 2 newly installed, 0 to remove and 479 not upgraded.
Need to get 343 kB of archives.
After this operation, 1,202 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
[more apt things showing installation]
19:25:22 wcarss@vm:~$ nginx -v
nginx version: nginx/1.4.6 (Ubuntu)19:47:54 wcarss@vm:/etc/nginx/sites-available$ sudo apt-get install php5-fpm Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: ax25-node libax25 openbsd-inetd Use 'apt-get autoremove' to remove them. Suggested packages: php-pear The following NEW packages will be installed: php5-fpm 0 upgraded, 1 newly installed, 0 to remove and 479 not upgraded. Need to get 2,193 kB of archives. After this operation, 9,248 kB of additional disk space will be used. [more apt things showing installation]
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/blog;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name localhost;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
# fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}(I'm not sure if I need the split_path_info, so it's commented for now)19:56:00 wcarss@vm:/etc/nginx/sites-available$ cd 19:56:05 wcarss@vm:~$ mkdir blog 19:56:07 wcarss@vm:~$ cd /usr/share/nginx 19:56:30 wcarss@vm:/usr/share/nginx$ sudo ln -sT /home/wcarss/blog blog 19:58:55 wcarss@vm:/usr/share/nginx$ sudo ln -sT /etc/nginx/sites-available/blog /etc/nginx/sites-enabled/blog 20:03:06 wcarss@vm:~/blog$ cd /etc/nginx/sites-enabled/ 20:03:16 wcarss@vm:/etc/nginx/sites-enabled$ ls blog default 20:03:19 wcarss@vm:/etc/nginx/sites-enabled$ sudo rm default 20:03:26 wcarss@vm:/etc/nginx/sites-enabled$ sudo service nginx restart * Restarting nginx nginx [ OK ]
<?php
php_info();
?>
20:15:31 wcarss@vm:~$ mysql -u root -p
Enter password:
[... some mysql jibber-jabber ...]
mysql> create database blog_app;
Query OK, 1 row affected (0.00 sec)
mysql> create user blog_app_user identified by 'sekret';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on blog_app.* to 'blog_app_user'@'localhost';
Query OK, 0 rows affected (0.21 sec)
mysql> flush_privileges;
mysql> Bye20:18:41 wcarss@vm:~$ mysql -u blog_app_user -p
Enter password:
[... mysql tellin' you how it is ...]
mysql> CREATE TABLE `posts` (
-> `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-> `title` varchar(1024) DEFAULT NULL,
-> `author_id` int(10) unsigned DEFAULT NULL,
-> `body` text,
-> `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-> `modified_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE `users` (
-> `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
-> `email` varchar(1024) DEFAULT NULL,
-> `username` varchar(128) DEFAULT NULL,
-> `password` varchar(2048) DEFAULT NULL,
-> `description` text,
-> `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
-> `modified_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)
mysql> show tables;
+--------------------+
| Tables_in_blog_app |
+--------------------+
| posts |
| users |
+--------------------+
2 rows in set (0.00 sec)
mysql> Byemysql> use blog_app;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> insert into users (email, username, password, description, created_at, modified_at) values ("carss.w@gmail.com", "wcarss", "sekret", "some dude", NOW(), NOW());
Query OK, 1 row affected (0.22 sec)
mysql> insert into posts (title, author_id, body, created_at, modified_at) values ("so it begins", 1, "this is a silly bunch of body text to begin with, but we've got to have SOMETHING now don't we??!!?!", NOW(), NOW());
Query OK, 1 row affected (0.00 sec)
mysql> insert into posts (title, author_id, body, created_at, modified_at) values ("post 2", 1, "yes, this is another sample post I've written. Shocking to say the least.", NOW(), NOW());
Query OK, 1 row affected (0.00 sec)
mysql> Bye<?php
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
echo "<h1>bloggggg</h1>\n\n";
foreach($db->query('select * from posts') as $row) {
echo "<h2>${row['title']}</h2>\n\n<p>${row['body']}</p>\n\n";
}
?>
<?php
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
echo '<html><body>';
echo '<h1>bloggggg</h1>';
foreach($db->query('select * from posts') as $row) {
echo "<h2>${row['title']}</h2><p>${row['body']}</p>";
}
echo '<form method="POST" action="/new.php">';
echo '<input type="text" name="title">';
echo '<input type="text" name="body">';
echo '<input type="submit" name="submit" value="submit">';
echo '</form>';
echo '</body></html>';
?><?php
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
$title = $_POST['title'];
$body = $_POST['body'];
$sql = "insert into posts (title, body, author_id) values (?, ?, 1);";
$db->prepare($sql)->execute([$title, $body]);
header('Location: http://localhost/index.php');
?><?php
if (isset($_POST['username']) && isset($_POST['password'])) {
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $db->prepare("select * from users where username = ?");
$stmt->execute([$username]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($results) === 1 && $results[0]['password'] === $password) {
echo "you logged in! yeahhhhhh!";
} else {
echo "wrong username or password!";
}
} else {
echo '<form method="POST" action="/login.php">';
echo ' <input type="text" name="username">';
echo ' <input type="password" name="password">';
echo ' <input type="submit" name="submit" value="submit">';
echo '</form>';
}
?><?php
session_start();
if (isset($_SESSION['user'])) {
echo "<small>hello, {$_SESSION['user']}! <a href='/logout.php'>logout</a></small>";
} else {
echo "<small>hello, unregistered user! <a href='/login.php'>login</a></small>";
}
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
echo '<html><body>';
echo '<h1>bloggggg</h1>';
foreach($db->query('select * from posts') as $row) {
echo "<h2>${row['title']}</h2><p>${row['body']}</p>";
}
echo '<form method="POST" action="/new.php">';
echo '<input type="text" name="title">';
echo '<input type="text" name="body">';
echo '<input type="submit" name="submit" value="submit">';
echo '</form>';
echo '</body></html>';
?><?php
session_start();
if (!isset($_SESSION['user'])) {
header('Location: http://localhost/login.php?not_logged=1');
exit;
}
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
$title = $_POST['title'];
$body = $_POST['body'];
if ($title !== "" and $body !== "") {
$sql = "insert into posts (title, body, author_id) values (?, ?, 1);";
$db->prepare($sql)->execute([$title, $body]);
}
header('Location: http://localhost');
?><?php
session_start();
if (isset($_SESSION['user'])) {
header('Location: http://localhost');
}
if (isset($_POST['username']) && isset($_POST['password'])) {
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $db->prepare("select * from users where username = ?");
$stmt->execute([$username]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($results) === 1 && $results[0]['password'] === $password) {
echo "you logged in! yeahhhhhh!";
$_SESSION['user'] = $username;
header('Location: http://localhost');
} else {
header('Location: http://localhost/login.php?wrong=1');
}
} else {
if (isset($_GET['wrong'])) {
echo "<h3>wrong username or password!</h3>";
}
if (isset($_GET['not_logged'])) {
echo "<h3>you need to be logged in to post!</h3>";
}
echo '<form method="POST" action="/login.php">';
echo ' <input type="text" name="username">';
echo ' <input type="password" name="password">';
echo ' <input type="submit" name="submit" value="submit">';
echo '</form>';
echo '<p>Back to <a href="/">home</a></p>';
}
?><?php
session_start();
if (isset($_SESSION['user'])) {
session_unset();
session_destroy();
}
header('Location: http://localhost');
?>picking back up a few days later in the morning
<?php
session_start();
if (!isset($_SESSION['user'])) {
header('Location: http://localhost/login.php?not_logged=1');
exit;
}
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
$id = $_POST['delete_post_id'];
$sql = "delete from posts where id=?";
$db->prepare($sql)->execute([$id]);
header('Location: http://localhost');
?><?php
session_start();
$logged_in = false;
if (isset($_SESSION['user'])) {
$username = $_SESSION['user'];
$logged_in = true;
}
if ($logged_in) {
echo "<small>hello, {$username}! <a href='/logout.php'>logout</a></small>";
} else {
echo "<small>hello, unregistered user! <a href='/login.php'>login</a></small>";
}
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
echo '<html><body>';
echo '<h1>bloggggg</h1>';
foreach($db->query('select * from posts') as $row) {
echo "<h2>${row['title']}</h2><p>${row['body']}</p>";
if ($logged_in) {
echo "<form method='POST' action='/delete.php'>";
echo " <input type='hidden' name='delete_post_id' value='${row['id']}'>";
echo " <input type='submit' name='submit' value='delete'>";
echo "</form>";
}
}
if ($logged_in) {
echo '<form method="POST" action="/new.php">';
echo '<input type="text" name="title">';
echo '<input type="text" name="body">';
echo '<input type="submit" name="submit" value="submit">';
echo '</form>';
}
echo '</body></html>';
?><?php
session_start();
if (!isset($_SESSION['user'])) {
header('Location: http://localhost/login.php?not_logged=1');
exit;
}
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
if (isset($_POST['title']) && isset($_POST['body']) && isset($_POST['edit_post_id'])) {
$id = $_POST['edit_post_id'];
$title = $_POST['title'];
$body = $_POST['body'];
$timestamp = (new DateTime())->format('Y-m-d H:i:s');
$sql = "update posts set title=?, body=?, modified_at=? where id=?";
$stmt = $db->prepare($sql)->execute([$title, $body, $timestamp, $id]);
header('Location: http://localhost');
} else if (isset($_GET['edit_post_id'])) {
$id = $_GET['edit_post_id'];
$sql = "select * from posts where id=?";
$stmt = $db->prepare($sql);
$stmt->execute([$id]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$title = htmlspecialchars($results[0]['title'], ENT_HTML5 | ENT_QUOTES);
$body = htmlspecialchars($results[0]['body'], ENT_HTML5 | ENT_QUOTES);
echo "<h2>edit post</h2>";
echo "<form method='POST' action='edit.php'>";
echo " <input type='text' name='title' value='$title'>";
echo " <input type='text' name='body' value='$body'>";
echo " <input type='hidden' name='edit_post_id' value='$id'>";
echo " <input type='submit' name='submit' value='submit'>";
echo "</form>";
echo "<p>Go <a href='index.php'>back</a></p>";
} else {
echo "<h2>no edit_post_id specified! Damnit Jim, I can't edit <em>nothing</em>!</h2>";
echo "<p>Go <a href='index.php'>home</a>";
}
?>// ... stuff you've seen before
foreach($db->query('select * from posts') as $row) {
echo "<h2>${row['title']}</h2><p>${row['body']}</p>";
if ($logged_in) {
echo "<a href='edit.php?edit_post_id=${row['id']}'>edit post</a>";
echo "<form method='POST' action='/delete.php'>";
// ... stuff you've seen before
<?php
session_start();
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
if (isset($_POST['edit_user_id']) && isset($_POST['edit_email']) && isset($_POST['edit_username']) && isset($_POST['edit_description'])) {
$id = $_POST['edit_user_id'];
if (!isset($_SESSION['username'])) {
header('Location: http://localhost/login.php?not_logged=1');
exit;
}
if ($id !== $_SESSION['user_id']) {
header('Location: http://localhost');
exit;
}
$email = $_POST['edit_email'];
$username = $_POST['edit_username'];
$description = $_POST['edit_description'];
$timestamp = (new DateTime())->format('Y-m-d H:i:s');
$sql = "update users set email=?, username=?, description=?, modified_at=? where id=?";
$params = [$email, $username, $description, $timestamp, $id];
if (isset($_POST['edit_password']) && $_POST['edit_password'] !== "") {
$password = $_POST['edit_password'];
$sql = "update users set email=?, username=?, password=?, description=?, modified_at=? where id=?";
$params = [$email, $username, $password, $description, $timestamp, $id];
}
$stmt = $db->prepare($sql)->execute($params);
$_SESSION['username'] = $username;
header('Location: http://localhost');
} else if (isset($_GET['edit_user_id'])) {
$id = $_GET['edit_user_id'];
if (!isset($_SESSION['username'])) {
header('Location: http://localhost/login.php?not_logged=1');
exit;
}
if ($id !== $_SESSION['user_id']) {
header('Location: http://localhost');
exit;
}
$sql = "select * from users where id=?";
$stmt = $db->prepare($sql);
$stmt->execute([$id]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$email = htmlspecialchars($results[0]['email'], ENT_HTML5 | ENT_QUOTES);
$username = htmlspecialchars($results[0]['username'], ENT_HTML5 | ENT_QUOTES);
$description = htmlspecialchars($results[0]['description'], ENT_HTML5 | ENT_QUOTES);
echo "<html><body>";
echo "<h2>edit post</h2>";
echo "<form method='POST' action='user.php'>";
echo " <p>email: <input type='text' name='edit_email' value='$email'><br>";
echo " username: <input type='text' name='edit_username' value='$username'><br>";
echo " description: <input type='text' name='edit_description' value='$description'><br>";
echo " password: <input type='password' name='edit_password' value=''><br>";
echo " <input type='hidden' name='edit_user_id' value='$id'>";
echo " <input type='submit' name='submit' value='submit'></p>";
echo "</form>";
echo "<p>Go <a href='index.php'>back</a></p>";
echo "</body></html>";
} else if (isset($_GET['user_id'])) {
$id = $_GET['user_id'];
$sql = "select * from users where id=?";
$stmt = $db->prepare($sql);
$stmt->execute([$id]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "<html><body>";
if (count($results) !== 1) {
echo "<p>Looks like somebody's barking up the wrong bush!</simpsons_reference><br>";
echo "(that user doesn't seem to exist.)</p>";
} else {
$email = htmlspecialchars($results[0]['email'], ENT_HTML5 | ENT_QUOTES);
$username = htmlspecialchars($results[0]['username'], ENT_HTML5 | ENT_QUOTES);
$description = htmlspecialchars($results[0]['description'], ENT_HTML5 | ENT_QUOTES);
echo "<h2>user: $username</h2>";
echo "<p>$email</p>";
echo "<p>$description</p>";
}
echo "<p>Go <a href='index.php'>home</a>";
echo "</body></html>";
} else {
echo "<html><body>";
echo "<p>Damnit jim! That's not enough information for me to do any good!</p>";
echo "<p>Go <a href='index.php'>home</a><br>";
echo "<small>and don't disappoint bones again</small></p>";
echo "</body></html>";
}
?><?php
session_start();
if (isset($_SESSION['username'])) {
header('Location: http://localhost');
exit;
}
if (isset($_POST['email']) && isset($_POST['username']) && isset($_POST['password']) && isset($_POST['description'])) {
# this is the most basic alternative to having a captcha that I could think of
if (!isset($_POST['access_code']) || $_POST['access_code'] !== 'sekret') {
header('Location: http://localhost');
exit;
}
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$description = $_POST['description'];
$db = new PDO('mysql:host=localhost;dbname=blog_app;charset=utf8', 'blog_app_user', 'sekret');
$sql = "insert into users (email, username, password, description) values (?, ?, ?, ?);";
$db->prepare($sql)->execute([$email, $username, $password, $description]);
header('Location: http://localhost/login.php');
} else {
echo '<html><head>';
echo ' <link href="style.css" rel="stylesheet" type="text/css">';
echo '</head><body>';
echo "<h2>new user</h2>";
echo "<form method='POST' action='signup.php'>";
echo " <p>email: <input type='text' name='email' placeholder='email'><br>";
echo " username: <input type='text' name='username' placeholder='username'><br>";
echo " description: <input type='text' name='description' placeholder='description'><br>";
echo " password: <input type='password' name='password' placeholder='password'><br>";
echo " access code: <input type='text' name='access_code' placeholder='access code'>";
echo " <input type='submit' name='submit' value='submit'></p>";
echo "</form>";
echo "<p>Go <a href='index.php'>back</a></p>";
echo "</body></html>";
}
?>G