"Clark Kent" said:Al sad me vuče da provan taj MAMP, izgleda mi fancy:-D
<html>
<body>
<h1>Dobar dan!</h1> <br>
<form action="login.php" method="post">
Username: <input type="text" name="username" size="20">
Password: <input type="text" name="password" size="20">
<input type="submit" value="Prijava" name="login">
</form>
</body>
</html>
<?PHP
//check that the user is calling the page from the login form and not accessing it directly
//and redirect back to the login form if necessary
if (!isset($username) || !isset($password))
{
header( "Location: index.php" );
}
//check that the form fields are not empty, and redirect back to the login page if they are
elseif (empty($username) || empty($password))
{
header( "Location: index.php" );
}
else
{
//convert the field values to simple variables
//add slashes to the username and md5() the password
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
//set the database connection variables
$dbHost = "localhost";
$dbUser = "dbuser";
$dbPass = "dbpass";
$dbDatabase = "dbname";
//connet to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$result=mysql_query("select * from Users where username='$user' AND password='$pass'", $db);
//check that at least one row was returned
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result))
{
//start the session and register a variable
session_start();
session_register('username');
//we will redirect the user to another page where we will make sure they're logged in
header( "Location: welcome.php" );
}
}
else
{
//if nothing is returned by the query, unsuccessful login code goes here...
header( "Location: index.php" );
}
}
?>
<?php
//start the session
session_start();
//check to make sure the session variable is registered
if(session_is_registered('username'))
{
echo "bravo!";
}
else
{
//the session variable isn't registered, send them back to the login page
header( "Location: index.php" );
}
?>
<html>
<head>
</head>
<body>
<h1>Logiran si!!</h1>
</body>
</html>
<?PHP
//check that the user is calling the page from the login form and not accessing it directly
//and redirect back to the login form if necessary
if (!isset($_POST['username']) || !isset($_POST['password']))
{
header( "Location: index.php" );
}
//check that the form fields are not empty, and redirect back to the login page if they are
elseif (empty($_POST['username']) || empty($_POST['password']))
{
header( "Location: index.php" );
}
else
{
//convert the field values to simple variables
//add slashes to the username and md5() the password
$user = addslashes($_POST['username']);
$pass = md5($_POST['password']);
//set the database connection variables
$dbHost = "localhost";
$dbUser = "dbuser";
$dbPass = "dbpass";
$dbDatabase = "dbname";
//connet to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$result=mysql_query("select * from Users where username='$user' AND password='$pass'", $db);
//check that at least one row was returned
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result))
{
//start the session and register a variable
session_start();
session_register($_POST['username']);
//we will redirect the user to another page where we will make sure they're logged in
header( "Location: welcome.php" );
}
}
else
{
//if nothing is returned by the query, unsuccessful login code goes here...
header( "Location: index.php" );
}
}
?>
<?php
//start the session
session_start();
//check to make sure the session variable is registered
if(session_is_registered($_POST['username']))
{
echo "bravo!";
}
else
{
//the session variable isn't registered, send them back to the login page
header( "Location: index.php" );
}
?>
<html>
<head>
</head>
<body>
<h1>Logiran si!!</h1>
</body>
</html>
error_reporting(2047);
ini_set("display_errors",1);
echo $user, '<br/>';
echo $pass, '<br>';
echo 'abc', $result['password'], '<br>';
$query = "select * from Users where username='$user' AND password='$pass'";
echo $query;
echo $query;
echo $result;
<?PHP
error_reporting(2047);
ini_set("display_errors",1);
//check that the user is calling the page from the login form and not accessing it directly
//and redirect back to the login form if necessary
if (!isset($_POST['username']) || !isset($_POST['password']))
{
// header( "Location: index.php" );
}
//check that the form fields are not empty, and redirect back to the login page if they are
elseif (empty($_POST['username']) || empty($_POST['password']))
{
// header( "Location: index.php" );
}
else
{
//convert the field values to simple variables
//add slashes to the username and md5() the password
$user = addslashes($_POST['username']);
echo $user, '<br/>';
$pass = md5($_POST['password']);
echo $pass, '<br>';
//set the database connection variables
$dbHost = "localhost";
$dbUser = "root";
$dbPass = "root";
$dbDatabase = "Strukture";
//connet to the database
$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database.");
mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
$query = "select * from korisnici where username='$user' AND password='$pass'";
$result=mysql_query($query, $db);
echo $result;
//check that at least one row was returned
$rowCheck = mysql_num_rows($result);
if($rowCheck > 0){
while($row = mysql_fetch_array($result))
{
//start the session and register a variable
session_start();
session_register($_POST['username']);
//we will redirect the user to another page where we will make sure they're logged in
// header( "Location: welcome.php" );
}
}
else
{
//if nothing is returned by the query, unsuccessful login code goes here...
// header( "Location: index.php" );
}
}
?>
session_register($_POST['username']);
$_SESSION['username'] = $_POST['username'];
$_SESSION['username'] = $user;
if($_SESSION['username'] = "john")
<html>
<body>
<h1>Niste logirani!!!</h1>
<form name="form1" method="post" action="login.php">
Username: <input name="myusername" type="text"><br>
Password: <input name="mypassword" type="password"><br>
<input type="submit" name="Submit" value="Login">
</form>
</body>
</html>
<?php
session_start();
ob_start();
$host = "localhost";
$username = "root";
$password = "root";
$db_name = "baza";
$db_tbl = "korisnici";
// spoji se na server i odaberi bazu
mysql_connect("$host", "$username", "$password") or die ("ne mogu se spojit na mysql");
mysql_select_db("$db_name") or die ("ne mogu odabrat bazu");
// definirajmo username i password korisnika koji se spaja na stranicu
$myusername = $_POST['myusername'];
$mypassword = $_POST['mypassword'];
// zastita od MySQL injekcije
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = "SELECT * FROM $db_tbl WHERE username = '$myusername' AND password = '$mypassword'";
$result = mysql_query($sql);
// pobrojimo pronadene retke
$count = mysql_num_rows($result);
// ako se rezultati slazu sa unesenim podacima broj redaka mora biti 1
if ($count == 1)
{
// registrirajmo korisnicke podatke i preusmjerimo na welcome.php
$_SESSION['myusername'] = $myusername;
header("location:welcome.php");
}
else
{
echo "<h1>Pogresni podaci...</h1>";
echo "<p><a href=\"index.php\">Pokusajte ponovno...</a></p>";
}
ob_end_flush();
?>
<?php
session_start();
if($_SESSION['myusername']) == "john")
{
session_unset();
session_destroy();
}
// šalji opet na logiranje
header("location:index.php");
?>
<?php
//start the session
session_start();
//check to make sure the session variable is registered
if($_SESSION['username'] != "john")
{
//the session variable isn't registered, send them back to the login page
header( "Location: index.php" );
}
?>
<html>
<body>
<h2>Aleluja!</h2>
<br>
<p>za odjebaus klikni <a href="logout.php">ovdje</a></p>
</body>
</html>
if($_SESSION['myusername']) == "john")
$user_key = sha1(time());