Blog
November 2024
- Uitleg pip en venv
- Uitleg self-made modules
- Uitleg externe apachelogs module (installatie pip)
- Uitleg pymysql
- Nieuwe user toevoegen mysql met permissies
- Connectie maken met db
# apachelog module
def connect(user, password, db):
con = pymysql.connect(host='localhost',
user=user,
password=password,
database=db,
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
return con
def write_to_db(con, filename):
fo = open(filename, 'rt')
parser = LogParser("%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"")
for line in fo:
try:
parser.parse(line)
print(str(entry.request_time), entry.request_line)
rl = entry.request_line.split(" ")
print(rl[0].strip("/"))
# Create a new record
with con.cursor() as cursor:
sql = "INSERT INTO `apache_log` (`useragent`, `time`, `method`, `page`) VALUES (%s, %s, %s, %s)"
cursor.execute(sql, (entry.headers_in["User-Agent"], entry.request_time.strftime("%Y-%m-%d %H:%M:%S"), rl[0], rl[1]))
# connection is not autocommit by default. So you must commit to save
# your changes.
con.commit()
except Exception as e:
print(e)
Augustus 2024
Uitleg over variabelen: Edutorial.nl -> Starten met PHP -> Variabelen
Uitleg over variabelen en loops:
For-loop van w3schools.com
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x \n";
}
Arrays:
$programmeertalen = ["PHP", "C#", "HTML", "JavaScript", "Java", "C++", "C"];
$programmeertalen[] = "Swift";
$programmeertalen[34] = "Python";
foreach ($programmeertalen as $x) {
echo "$x \n";
}
Een webserver starten vanuit een willekeurige map:
php -S localhost:8877
Februari 2024
Uitleg inloggen met php:
<?php
var_dump($_POST);
echo $_POST["login"];
echo $_POST["password"];
$users = [
"Jan" => "123",
"Kees" => "456"
];
foreach($users as $username => $password) {
if($username == $_POST['login']) {
echo "Goed bezig!";
}
}