Plik: login_form.php:
Code: Zaznacz cały
<html>
<head>
<title>Logowanie</title>
</head>
<body>
<form method="post" action="proces_login.php">
Login: <input type="text" name="login">
Hasło:<input type="password" name="password">
<input type="submit" value="Zaloguj">
</form>
</body>
</html>
Code: Zaznacz cały
<?php
session_start();
if (!isset($_POST['login']) && !isset($_POST['password']) || ($_POST['login'] == '' && $_POST['password'] == ''))
{
header('Location: login_form.php');
session_destroy();
exit;
}
include("database.php");
include("users.php");
$author = getAutor( $_POST['login'], $_POST['password']);
if($author === FALSE) {
header('Location: login_form.php');
session_destroy();
exit;
}
foreach ($author as $klucz => $wartosc) {
if(!is_numeric($klucz)){
$_SESSION[$klucz] = $wartosc;
}
}
header("Location: index.php");
?>
Code: Zaznacz cały
<?php
session_start();
$userLogged = false;
if ( isset ($_SESSION['id']))
{
$userLogged = true;
}
?>
<html>
<head>
<title>Strona główna</title>
</head>
<body>
<?php
if ($userLogged){
echo("<a href='logout.php'>Wyloguj</a> <br><br>");
echo("<a href='add_wpis.php'>Dodaj wpis</a><br><br>");
echo("<a href='edit_wpis.php'>Edytuj wpis</a><br><br>");
}
else {
include("login_form.php");
}
include("database.php");
$sql = "SELECT wpisy.tresc, wpisy.data, wpisy.id as wpisy_id FROM wpisy
";
$result = mysql_query($sql) or die(mysql_error());
//tutaj skończyłem
while ($row = mysql_fetch_array($result)){
echo ("opublikowane: $row[data]");
if ($row[id] == $_SESSION['id']){
echo("<a href='edit_wpis.php?advert_id=" .$row['wpisy_id'] ."'> Edytuj</a>");
echo ("<a href='delete_advertisment.php?advert_id=" .$row['wpis_id']. "'> Kasuj</a>");
}
echo ("<br> $row[tresc] <br><hr>");
}
?>
</body>
</html>
Code: Zaznacz cały
<?php
session_start();
$userLogged = false;
if( isset($_SESSION['id'])){
$userLogged = true;
}
else{
session_destroy();
header("Location: index.php");
exit;
}
if(!isset($_GET['wpisy_id'])){
header("Location: index.php");
exit;
}
include("database.php");
$sql = "SELECT * from wpisy where id= $_GET[wpisy_id]";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$wpis_saved = false;
if(isset($_POST['advert'])){
include ("database.php");
$sql = "UPDATE wpisy SET tresc = '$_POST[advert]', data = NOW() where id = $_GET[wpisy_id]";
}
?>
<html>
<head>
<title>Edytuj wpis</title>
</head>
<body>
<?php
if (wpis_saved){
echo ( "Wpis zapisany <a href='index.php'>Strona Główna</a>");
}
?>
<form method="post" action="<?php echo ( $_SERVER['PHP_SELF']); ?>">
<input type="text" name="advert">
<input type="submit">
</form>
</body>
</html>
Code: Zaznacz cały
<?php
session_start();
$userLogged = false;
if (isset($_SESSION['id'])){
$userLogged = true;
}
else{
session_destroy();
header("Location: index.php");
exit;
}
$wpis_saved = false;
if(isset($_POST['advert'])){
include( "database.php");
$sql = " INSERT INTO wpisy SET
tresc = '$_POST[advert]',
data = NOW()
";
if(mysql_query($sql) or die(mysql_error())){
$wpis_saved = true;
}
}
?>
<html>
<head>
<title>Dodawanie wpisu</title>
</head>
<body>
<?
if($wpis_saved){
echo ("Wpis został dodany <a href='index.php'> Strona główna</a>");
}
?>
<form method="post" action="<?php echo ( $_SERVER['PHP_SELF']); ?>">
<input type="text" name="advert">
<input type="submit">
</form>
</body>
</html>
Code: Zaznacz cały
<?php
function getAutor ($login, $password)
{
$sql = "SELECT * FROM autor where name= '$login' and password = '$password'";
$result = mysql_query($sql);
if ($result === FALSE) {
return FALSE;
}
while ($row = mysql_fetch_array ($result))
{
return $row;
}
return false;
}
?>
Code: Zaznacz cały
<?php
session_start();
session_destroy();
header("Location: index.php");
exit;
?>
Moja baza danych to:
Tabela autor (id, name, password, email)
Tabela wpisy(id, tresc, data)
Proszę o pomoc