<?php
// ====== Database-tilkobling ======
$db_host = 'localhost';
$db_user = 'root'; // Endre til din bruker
$db_pass = ''; // Endre til ditt passord
$db_name = 'codelens';
try {
$pdo = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8mb4", $db_user, $db_pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch(PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
// Hent eller opprett session_id for gjesten
function getSessionId() {
if (!isset($_SESSION['codelens_session'])) {
$_SESSION['codelens_session'] = session_id() . '_' . time();
}
return $_SESSION['codelens_session'];
}
// Hent lagret kode fra database
function getStoredCode($pdo, $session_id) {
$stmt = $pdo->prepare("SELECT html_code, css_code, js_code FROM code_snapshots WHERE session_id = ? ORDER BY id DESC LIMIT 1");
$stmt->execute([$session_id]);
return $stmt->fetch();
}
// Lagre kode til database
function saveCode($pdo, $session_id, $html, $css, $js) {
// Sjekk om det finnes allerede
$stmt = $pdo->prepare("SELECT id FROM code_snapshots WHERE session_id = ?");
$stmt->execute([$session_id]);
$exists = $stmt->fetch();
if ($exists) {
$stmt = $pdo->prepare("UPDATE code_snapshots SET html_code = ?, css_code = ?, js_code = ? WHERE session_id = ?");
return $stmt->execute([$html, $css, $js, $session_id]);
} else {
$stmt = $pdo->prepare("INSERT INTO code_snapshots (session_id, html_code, css_code, js_code) VALUES (?, ?, ?, ?)");
return $stmt->execute([$session_id, $html, $css, $js]);
}
}
// Nullstill kode til original
function resetCode($pdo, $session_id) {
$stmt = $pdo->prepare("DELETE FROM code_snapshots WHERE session_id = ?");
return $stmt->execute([$session_id]);
}
?>
( ! ) Warning: Undefined variable $file in C:\wamp64\www\php.karimy.no\tools\codelens1\index.php on line 246
| Call Stack |
| # | Time | Memory | Function | Location |
| 1 | 0.0003 | 362480 | {main}( ) | ...\index.php:0 |
| 2 | 0.0010 | 365224 | show_code_viewer( $filename = 'db.php', $content = '<?php\r\n// ====== Database-tilkobling ======\r\n$db_host = \'localhost\';\r\n$db_user = \'root\'; // Endre til din bruker\r\n$db_pass = \'\'; // Endre til ditt passord\r\n$db_name = \'codelens\';\r\n\r\ntry {\r\n $pdo = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8mb4", $db_user, $db_pass);\r\n $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\r\n $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);\r\n} catch(PDOException $e) {\r\n die("Database connection failed: " . $e->getMessag'..., $ext = 'php' ) | ...\index.php:39 |
| ( ! ) Deprecated: dirname(): Passing null to parameter #1 ($path) of type string is deprecated in C:\wamp64\www\php.karimy.no\tools\codelens1\index.php on line 246 |
| Call Stack |
| # | Time | Memory | Function | Location |
| 1 | 0.0003 | 362480 | {main}( ) | ...\index.php:0 |
| 2 | 0.0010 | 365224 | show_code_viewer( $filename = 'db.php', $content = '<?php\r\n// ====== Database-tilkobling ======\r\n$db_host = \'localhost\';\r\n$db_user = \'root\'; // Endre til din bruker\r\n$db_pass = \'\'; // Endre til ditt passord\r\n$db_name = \'codelens\';\r\n\r\ntry {\r\n $pdo = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8mb4", $db_user, $db_pass);\r\n $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\r\n $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);\r\n} catch(PDOException $e) {\r\n die("Database connection failed: " . $e->getMessag'..., $ext = 'php' ) | ...\index.php:39 |
| 3 | 0.0041 | 366384 | dirname( $path = NULL ) | ...\index.php:246 |
" class="btn">
Tilbake
( ! ) Warning: Undefined variable $file in C:\wamp64\www\php.karimy.no\tools\codelens1\index.php on line 249
| Call Stack |
| # | Time | Memory | Function | Location |
| 1 | 0.0003 | 362480 | {main}( ) | ...\index.php:0 |
| 2 | 0.0010 | 365224 | show_code_viewer( $filename = 'db.php', $content = '<?php\r\n// ====== Database-tilkobling ======\r\n$db_host = \'localhost\';\r\n$db_user = \'root\'; // Endre til din bruker\r\n$db_pass = \'\'; // Endre til ditt passord\r\n$db_name = \'codelens\';\r\n\r\ntry {\r\n $pdo = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8mb4", $db_user, $db_pass);\r\n $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\r\n $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);\r\n} catch(PDOException $e) {\r\n die("Database connection failed: " . $e->getMessag'..., $ext = 'php' ) | ...\index.php:39 |
| ( ! ) Deprecated: urlencode(): Passing null to parameter #1 ($string) of type string is deprecated in C:\wamp64\www\php.karimy.no\tools\codelens1\index.php on line 249 |
| Call Stack |
| # | Time | Memory | Function | Location |
| 1 | 0.0003 | 362480 | {main}( ) | ...\index.php:0 |
| 2 | 0.0010 | 365224 | show_code_viewer( $filename = 'db.php', $content = '<?php\r\n// ====== Database-tilkobling ======\r\n$db_host = \'localhost\';\r\n$db_user = \'root\'; // Endre til din bruker\r\n$db_pass = \'\'; // Endre til ditt passord\r\n$db_name = \'codelens\';\r\n\r\ntry {\r\n $pdo = new PDO("mysql:host=$db_host;dbname=$db_name;charset=utf8mb4", $db_user, $db_pass);\r\n $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\r\n $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);\r\n} catch(PDOException $e) {\r\n die("Database connection failed: " . $e->getMessag'..., $ext = 'php' ) | ...\index.php:39 |
| 3 | 0.0059 | 366384 | urlencode( $string = NULL ) | ...\index.php:249 |
&raw=1" class="btn btn-primary" target="_blank">
Åpne raw
Gå til læring