Parašė IGEN· 2012 Vas. 20 00:02:10
#7
Nieks neziuri tos temos bet p*.
Ant prikolo uzmesiu, pagalvos is jusu nesitikiu :/
register.php
<?php
//tikrinama ar ivydyta forma
if(isset($_POST['username']))
{
//priskiriami kintamieji
$user = $_POST['username'];
$pass = $_POST['password'];
$pass2 = $_POST['password2'];
//tikrina ar nera tusciu lauku
if($user<>"" AND $pass<>"" AND $pass2<>"")
{
//tikrina ar vienodi slaptazodziai
if($pass==$pass2)
{
if(strlen($pass)>=4)
{
$con = mysql_connect("localhost", "root", "");
if(!$con)
{
die("could not connect:".mysql_error());
}
mysql_select_db("real", $con);
$pass = md5($pass);
if(mysql_num_rows(mysql_query("select * from users where username = '$user'")))
{
echo "vartotojas uzimtas";
}else{
mysql_query("insert into users (uid, username, password) VALUES ('', '$user', '$pass')");
echo "Sekminga uzsiregistravote.";
}
}else{
echo "Slaptazodis per trumpas";
}
}else{
echo "Slaptazodziai nesutampa";
}
}else{
echo "Ne visi laukai uzpildyti";
}
}
?>
<form method='POST'>
username <input type='text' name='username'><br>
Password <input type='password' name='password'><br>
Passwordx2 <input type='password' name='password2'><br>
<br>
<input type='submit' value='Register'>
</form>
login.php
<?php
if(isset($_GET['logout']))
{//logout
$expire=time()-60*60*24*30;//1 month
setcookie("uid", "", $expire);
}
if(isset($_POST['user']))
{
$user = $_POST['user'];//Laimonas
$pass = md5($_POST['pass']);//12345
//Connect to server
$con = mysql_connect("localhost", "root", "");
if(!$con){die('Could not connect: '. mysql_error());}
//select db
mysql_select_db("real", $con);
//check or exist
if(mysql_num_rows(mysql_query("SELECT * FROM users where username = '$user' AND password = '$pass'")))
{//User exist.
$result = mysql_query("SELECT * FROM users where username = '$user' AND password = '$pass'");
while($row = mysql_fetch_array($result))
{
$expire=time()+60*60*24*30;//1 month
setcookie("uid", $row['uid'], $expire);
$userID = $row['uid'];
echo "Prisijungete sekmingai <b>".$row['username']."</b><br>";
}
}else{
//wrong username or password
echo "<b> Neteisingas vartotojo vardas arba slaptazodis</b><br><br>";
}
mysql_close($con);
}
if(isset($_COOKIE['uid']))
{
$userID = $_COOKIE['uid'];
}
if(isset($userID))
{
if(!isset($_GET['logout'])){
echo "Hello (<a href='?logout'>Atsijungti</a>)";
}else{
echo "<form method='post' action='login.php'>
Vartotojo vardas<br><input type='text' name='user'><br>
Slaptažodis<br><input type='password' name='pass'><br>
<input type='submit' value='Prisijungti'>
</form>";
}
}else{
echo "<form method='post' action='login.php'>
Vartotojo vardas<br><input type='text' name='user'><br>
Slaptažodis<br><input type='password' name='pass'><br>
<input type='submit' value='Prisijungti'>
</form>";
}//---
?>