<?php
session_start();
header("Cache-control: private");
?>
<html>
<head>
<title>Logged-in</title>
</head>
<body>
<?php
$datafile="data.txt"; //name of the data file
if($_GET['action'] == "login") {
if(!isset($_POST['username']) || !isset($_POST['password'])){ //this checks that all the fields are filled in
error_message("One or more required fields were left blank!", $username, $password);
}
$file = file($datafile);
while(list(,$value) = each($file)) {
list($fname,$femail,$furl,$fuser,$fpass,$blank) = explode('|', $value);
if($_POST['username'] == $fuser && $_POST['password'] == $fpass){
$_SESSION['name'] = $fuser;
$_SESSION['realname'] = $fname;
$_SESSION['url'] = $furl;
$_SESSION['email'] = $femail; //adds the users data to the php session
$_SESSION['pass'] = $fpass;
//insert html for sucessfull log on here
//you can use . $_SESSION['name'] . for username
// replace name with realname, url, email to display different name
?>
Ти си влязъл.<br>
Виж профила си от <a href="profile.php">тук</a><br>
или излез от <a href="logout.php">тук</a>.
</body>
</html>
<?php
$logink = true;
}
}
if($logink !== true) {
?>
Грешна парола или потребителско име !
<?
}
} elseif($_GET['action'] == 'change') {
if(!isset($_POST['name']) || !isset($_POST['email']) || !isset($_POST['url']) || !isset($_POST['newpass'])) {
//this checks that all the fields are filled in
?>
all fields were not filled in
<?
}
$file = file($datafile);
while(list(,$value) = each($file)){
list($fname,$femail,$furl,$fuser,$fpass) = explode('|', $value);
if($_SESSION['name'] == $fuser){
//opens data file to change it
$oldword = "$fname|$femail|$furl|$fuser|$fpass|";
$newword = $_POST['name'] . '|' . $_POST['email'] . '|' . $_POST['url'] . '|' . $_SESSION['name'] . '|' . $_POST['newpass'] . '|';
$fp = fopen($datafile, 'r');
$data = fread($fp, filesize($datafile));
fclose($fp);
$newdata = str_replace($oldword, $newword, $data);
$fp = fopen($datafile, 'w');
fwrite($fp,$newdata) or die ('error writing');
fclose($fp);
$succ = true; //data changed sucessfully
?>
Всичко беше променено успешно моля <a href="user.php">влез</a>
<?
$_SESSION['name'] = FALSE;
$_SESSION['pass'] = FALSE;
$_SESSION['url'] = FALSE;
$_SESSION['realname'] = FALSE;
$_SESSION['email'] = FALSE;
}
}
if($succ !== true) {
?>
Влизането неупешно -грешно име или парола
<?
}
} else {
exit;
}
?>