Källkod
Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.
webbserverprogrammering/projects/typr/
14 filer
create_tables.php
dbconnection.php
getUrl.php
index.php
notes.txt
plan.php
profile.php
redovisning.html
resources/
session_check.php
styles/
sv_200.txt
sv_829.txt
test.php
dbconnection.php
getUrl.php
index.php
notes.txt
plan.php
profile.php
redovisning.html
resources/
session_check.php
styles/
sv_200.txt
sv_829.txt
test.php
create_tables.php
65 lines ASCII Windows (CRLF)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
function dump($dump) {
echo "<pre>";
var_dump($dump);
echo "</pre>";
}
$tableSuccess = true;
$tableAlreadyExists = false;
$userinsertSuccess = true;
$userAlreadyExists = false;
$sql = "CREATE TABLE typr_users (
user_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(255) UNIQUE,
password VARCHAR(255),
email VARCHAR(255),
profile_image_path VARCHAR(255),
usertype VARCHAR(255),
create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_login_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
online_status VARCHAR(255)
)";
include('dbconnection.php');
try {
$dbconn->exec($sql);
} catch (PDOException $e) {
$tableSuccess = false;
if ($e->errorInfo[0] === "42S01")
$tableAlreadyExists = true;
}
$sql = "INSERT INTO typr_users (username, password, email, profile_image_path, usertype, online_status) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $dbconn->prepare($sql);
try {
$stmt->execute(["admin", password_hash("admin", PASSWORD_DEFAULT), "some.fake.address@gmail.com", "", "admin", "offline"]);
} catch (PDOException $e) {
$userinsertSuccess = false;
if ($e->errorInfo[0] === "23000")
$userAlreadyExists = true;
}
if ($tableSuccess) {
echo "Created table <strong>typr_users</strong>, I think!<br>";
}
if ($tableAlreadyExists) {
echo "Table already exists.<br>";
}
if ($userinsertSuccess)
echo "Inserted default admin user<br>";
if ($userAlreadyExists)
echo "Duplicate username!<br>";
?>