Kod
<?php
//starting a fresh session
session_start();
header("Cache-control: private");
$datafile="data.php";
if($_GET['action'] == "login") {
if(!isset($_POST['username']) || !isset($_POST['password'])){
error_message("<FONT face=arial color=778899 size=2>Jedno lub więcej wymaganych pól jest puste!</FONT>", $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;
?>
przykladowy tekst
<?php
$logink = true;
}
}
if($logink !== true) {
?>
Bł±d logowania, zły login lub hasło!
<?
}
} 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){
$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
?>
<FONT face=arial color=778899 size=2>Twój profil został zmieniony! Proszę się <a href="index.php?show=user">zalogować</a></FONT>
<?
$_SESSION['name'] = FALSE;
$_SESSION['pass'] = FALSE;
$_SESSION['url'] = FALSE;
$_SESSION['realname'] = FALSE;
$_SESSION['email'] = FALSE;
}
}
if($succ !== true) {
?>
Bł±d logowania, zły login lub hasło!
<?
}
} else {
}
?>
//starting a fresh session
session_start();
header("Cache-control: private");
$datafile="data.php";
if($_GET['action'] == "login") {
if(!isset($_POST['username']) || !isset($_POST['password'])){
error_message("<FONT face=arial color=778899 size=2>Jedno lub więcej wymaganych pól jest puste!</FONT>", $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;
?>
przykladowy tekst
<?php
$logink = true;
}
}
if($logink !== true) {
?>
Bł±d logowania, zły login lub hasło!
<?
}
} 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){
$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
?>
<FONT face=arial color=778899 size=2>Twój profil został zmieniony! Proszę się <a href="index.php?show=user">zalogować</a></FONT>
<?
$_SESSION['name'] = FALSE;
$_SESSION['pass'] = FALSE;
$_SESSION['url'] = FALSE;
$_SESSION['realname'] = FALSE;
$_SESSION['email'] = FALSE;
}
}
if($succ !== true) {
?>
Bł±d logowania, zły login lub hasło!
<?
}
} else {
}
?>
a to plik user.php
Kod
<form name="login" method="post" action="login.php?action=login">
<TABLE BORDER=0 align="center"><TR>
<TD width="71" align="left"><FONT face=arial color=778899 size=2>Login:</TD>
<TD><input class="txtstyle" type="text" name="username" style="font-family: arial; font-size: 9;" SIZE="9">
</TD></TR>
<TR><TD width="69" align="left"><FONT face=arial color=778899 size=2>Hasło:</TD>
<TD><input class="txtstyle" type="password" name="password" style="font-family: arial; font-size: 9;" SIZE="9">
</TD></TR></TABLE>
<center><input class="button" type="submit" name="Submit" style="font-family: arial; font-size: 10;" value="Zaloguj"></center></form>
<center><FONT face=arial color=778899 size=2><a href="index.php?show=signup">Zarejestruj się</a></FONT></center>
<TABLE BORDER=0 align="center"><TR>
<TD width="71" align="left"><FONT face=arial color=778899 size=2>Login:</TD>
<TD><input class="txtstyle" type="text" name="username" style="font-family: arial; font-size: 9;" SIZE="9">
</TD></TR>
<TR><TD width="69" align="left"><FONT face=arial color=778899 size=2>Hasło:</TD>
<TD><input class="txtstyle" type="password" name="password" style="font-family: arial; font-size: 9;" SIZE="9">
</TD></TR></TABLE>
<center><input class="button" type="submit" name="Submit" style="font-family: arial; font-size: 10;" value="Zaloguj"></center></form>
<center><FONT face=arial color=778899 size=2><a href="index.php?show=signup">Zarejestruj się</a></FONT></center>