Jump to content
php.lv forumi

Password protekt ar seesion


ziedinjsh

Recommended Posts

index.php


session_start();
$password = "nekas"; 

if (isset($_POST['enter'])){

if ($password == $password) {
echo "<span style='color:#000000'><b>parole nepareiza</b></span>";
}else{

$_SESSION['producer'] = $row['p'];
echo "<meta http-equiv='refresh' content='0;url=page.php'>";
}

}

echo "<form method='POST' action='".$_SERVER['PHP_SELF']."'>";
echo "<input type='password' name='password'>";
echo "<input type='submit' name='enter' value='Enter'>";
echo "</form>";

 

page.php

session_start();

if ($_SESSION['p']){
echo "esmu iekša";

echo "<a href='logout.php'>Iziet</a>";

}else{

echo "<meta http-equiv='refresh' content='0;url=index.php'>";

}

 

man visu laiku rāda ka ir nepareiza parole kas pa vainu

 

Paldies jau iepriekš :)

Edited by ziedinjsh
Link to comment
Share on other sites

Tas tādēļ, ka ļoti savdabīga programmas loģika...

if ($password == $password) { // Ja mainīgajā $passsword ir ierakstīts tas pats, kas mainīgajā... $password
echo "<span style='color:#000000'><b>parole nepareiza</b></span>"; //Tad pateikt, ka parole nav pareiza
}else{//Bet visos gadījumos, kad $password nesakrīt pats ar sevi uzskatīt, ka parole ir varen laba

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...