08 Manaxhimi i gjendjes

Ne kete leksion

login.php

<html>

<head>

<title>Login Form</title>

<script language="JavaScript">

function kontrollo()

{

if (document.loginfrm.user.value=='')

{ // begin

alert('Futni username');

document.loginfrm.user.focus();

return false;

} //end


if (document.loginfrm.pass.value=='')

{

alert('Futni password');

document.loginfrm.pass.focus();

return false;

}


return true;

}

</script>

</head>

<body>

<form name="loginfrm" method="post" action="checklogin.php" onSubmit="return kontrollo();" >

<p> Username

<input name="user" type="text" id="user">

</p>

<p>Password

<input name="pass" type="password" id="pass">

</p>

<p>

<input type="submit" name="Submit" value="---LOGIN---">

<input type="reset" name="Submit2" value="---CLEAR---">

</p>

</form>

</body>

</html>

checklogin.php

<?php

include('start.php');

include('db.php');

$u=$_REQUEST['user'];

$p=$_REQUEST['pass'];

$sql=" select * from users

where

username='$u'

and

password='$p'

";

// te ekzekutojme SQL dinamike

$res=mysql_query($sql)

or die('gabim komande');

$n=mysql_num_rows($res);

if($n==0)

{

echo '<div class="error">username ose password jane futur gabim</div>';

include('login.php');

}

else

{

$_SESSION['u']=$u;

header("location:index.php");

}

?>

start.php

<?php

session_start();

?>

kontrollo.php

<?php

if(!isset($_SESSION['u']))

{

echo '<p>hyrje e pa autorizuar</p>';

include("login.php");

exit();

}

?>

db.php

<?php

// te lidhemi me serverin

mysql_connect('localhost','root','')

or die('nuk lidhem dot me serverin');

mysql_select_db('mydb')

or die('nuk zgjedh dot db');

?>

Ruatja e gjendjes

faqe1.php ( versioni 1)

<?php

if(isset($i))

{

$counter=$i;

}

else

{

$counter=0;

}

echo "<p>Vlera e counter para inkeremetimit: $counter </p>";

$counter++;

echo "<p>Vlera e counter pas inkeremetimit: $counter </p>";

$i=$counter;

?>

<p>

<a href="faqe1.php">ne vend te F5</a>

</p>

faqe1.php Versioni 2

<?php

session_start();

if(isset($_SESSION['i']))

{

$counter=$_SESSION['i'];

}

else

{

$counter=0;

}

echo "<p>Vlera e counter para inkeremetimit: $counter </p>";

$counter++;

echo "<p>Vlera e counter pas inkeremetimit: $counter </p>";

$_SESSION['i']=$counter;

?>

<p>

<a href="faqe1.php">ne vend te F5</a>

</p>

<p>

<a href="destroy.php?page=faqe1.php">Logout</a>

</p>