24-09-2011, 14:02
Kod:
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>test</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="main">
<?php
if (empty($_POST) && isset($_GET['action'])) {
$action = $_GET['action'];
switch ($action) {
case 'logout':
session_unset();
session_destroy();
break;
}
}
if (!isset($_SESSION['user'])) {
$user = '';
$pass = '';
if (isset($_POST['login'])) {
$user = strtolower(trim($_POST['user']));
$pass = $_POST['pass'];
$errors = array();
if ($user == '' || $user != 'admin') {
$errors['user'] = '';
}
if ($pass == '' || $pass != '123456') {
$errors['pass'] = '';
}
if (empty($errors)) {
$_SESSION['user'] = $user;
} else {
echo '<p class="error">Please fill in your correct ';
if (isset($errors['user']))
echo 'username';
if (count($errors) == 2)
echo ' and ';
if (isset($errors['pass']))
echo 'password';
echo '.</p>', "\n";
}
}
}
if (isset($_SESSION['user'])) {
$user = $_SESSION['user'];
?>
<div id="headertext">
<p class="l">You are logged in as <strong><?php echo $user?></strong>.</p>
<p class="r"><a href="?action=logout">Logout</a></p>
</div>
<?php
if (isset($_POST['edit'])) {
if (file_put_contents('../index.php', $_POST['homecontent']))
echo '<p class="succes">Your changes are saved.</p>', "\n";
}
$homecontent = file_get_contents('../index.php');
?>
<form method="post" action="">
<p>Here you can edit your homepage text:</p>
<textarea name="homecontent" id="homecontent" rows="20" cols="55"><?php echo $homecontent?></textarea>
<p><button type="submit" name="edit">Save changes</button></p>
<button onclick="document.getElementById('homecontent').value='<?PHP include(\'strony/gora.txt\');?>';">DOdaj</button>
?>
</form>
<?php } else {?>
<form method="post" action="" id="login">
<p>
<label for="user">Username:</label><input type="text" name="user" id="user" value="<?php echo $user?>" />
</p>
<p>
<label for="pass">Password:</label><input type="password" name="pass" id="pass" value="<?php echo $pass?>" />
</p>
<p>
<button type="submit" name="login">Login</button>
</p>
</form>
<?php }?>
</div>
</body>
</html>
Proszę, cała strona... nie mam pojęcia co jest źle, bo w PHP się prawie wcale nie orientuję :/
Cytat:The sky is falling, I don't care
I just want to feel good!
Her train's leaving, she don't care
She just wants to feel good!
The World is dying, we don't care
They just want to feel good!
It's all over, we don't care
We just want to feel good!