Autentimise näide php sessiooniga: erinevus redaktsioonide vahel
Mine navigeerimisribale
Mine otsikasti
Resümee puudub |
Resümee puudub |
||
| 31. rida: | 31. rida: | ||
$con = | $con = mysqli_connect("localhost","st2014","progress","st2014"); | ||
if (!$con) { | if (!$con) { | ||
die('Could not connect: ' . mysql_error()); | die('Could not connect: ' . mysql_error()); | ||
} | } | ||
$ | $email = "X"; | ||
$auth=0; | $auth=0; | ||
if (isset($_REQUEST['username'])) { | if (isset($_REQUEST['username'])) { | ||
| 47. rida: | 45. rida: | ||
$password = $_REQUEST['password']; | $password = $_REQUEST['password']; | ||
} | } | ||
if (isset($_REQUEST[' | if (isset($_REQUEST['email'])) { | ||
$ | $email = $_REQUEST['email']; | ||
} | } | ||
$aq = "select username from | $aq = "select username from tt1v1_users where username='$username' and password='$password'"; | ||
$result = | $result = mysqli_query($con,$aq); | ||
if (! | if (! mysqli_fetch_array($result)) { | ||
$auth=0; | $auth=0; | ||
echo('<p>wrong username, try again!!<p>'); | echo('<p>wrong username, try again!!<p>'); | ||
| 72. rida: | 70. rida: | ||
</form> | </form> | ||
<p> | <p> | ||
<?php | <?php | ||
echo "tere " . $username . "<p>"; | echo "tere " . $username . "<p>"; | ||
$q="SELECT * from | $q="SELECT * from tt1v1_users where email='$email'"; | ||
echo "query: $q <br>"; | echo "query: $q <br>"; | ||
$result = | $result = mysqli_query($con,$q); | ||
echo "leitud:<p>"; | echo "leitud:<p>"; | ||
while($row = | while($row = mysqli_fetch_array($result)) { | ||
echo $row['username'] . " " . $row[' | echo $row['username'] . " " . $row['fullname']; | ||
echo "<br />"; | echo "<br />"; | ||
} | } | ||
} | } | ||
mysqli_close($con); | |||
?> | ?> | ||
| 98. rida: | 97. rida: | ||
<input type="text" name="username"><p> | <input type="text" name="username"><p> | ||
parool: <input type="password" name="password"><p> | parool: <input type="password" name="password"><p> | ||
otsitav email: <input type="text" name="email" autocomplete="off"><br> | |||
<?php | <?php | ||
} else { | } else { | ||
?> | ?> | ||
<p> | <p> | ||
<?php | <?php | ||
} | } | ||
| 112. rida: | 111. rida: | ||
Lopp. | Lopp. | ||
</body> | </body> | ||
</pre> | </pre> | ||
Viimane redaktsioon: 9. detsember 2014, kell 14:09
Töötavana vt http://dijkstra.cs.ttu.ee/~tammet/k18.php (proovi kasutaja tanel parool lenat)
<?php
session_start();
// Use $HTTP_SESSION_VARS with PHP 4.0.6 or less
if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0;
} else {
$_SESSION['count']++;
echo $_SESSION['count'];
echo '<p>';
}
$username="X";
$password="X";
if (isset($_REQUEST['logout'])) {
session_destroy();
die("Head aega!");
}
if (isset($_SESSION['username']) && isset($_SESSION['password'])) {
$username=$_SESSION['username'];
$password=$_SESSION['password'];
}
?>
Algus.
<p>
<?php
$con = mysqli_connect("localhost","st2014","progress","st2014");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$email = "X";
$auth=0;
if (isset($_REQUEST['username'])) {
$username = $_REQUEST['username'];
}
if (isset($_REQUEST['password'])) {
$password = $_REQUEST['password'];
}
if (isset($_REQUEST['email'])) {
$email = $_REQUEST['email'];
}
$aq = "select username from tt1v1_users where username='$username' and password='$password'";
$result = mysqli_query($con,$aq);
if (! mysqli_fetch_array($result)) {
$auth=0;
echo('<p>wrong username, try again!!<p>');
} else {
$auth=1;
$_SESSION['username']=$username;
$_SESSION['password']=$password;
}
if ($auth) {
echo "Tere $username!"
?>
<form>
<input type="hidden" name="logout" value="yes">
<input type="submit" value="Logi valja">
</form>
<p>
<?php
echo "tere " . $username . "<p>";
$q="SELECT * from tt1v1_users where email='$email'";
echo "query: $q <br>";
$result = mysqli_query($con,$q);
echo "leitud:<p>";
while($row = mysqli_fetch_array($result)) {
echo $row['username'] . " " . $row['fullname'];
echo "<br />";
}
}
mysqli_close($con);
?>
<form method="post">
<?php
if(!$auth) {
?>
sinu kasutajatunnus:
<input type="text" name="username"><p>
parool: <input type="password" name="password"><p>
otsitav email: <input type="text" name="email" autocomplete="off"><br>
<?php
} else {
?>
<p>
<?php
}
?>
<input type="submit">
</form>
<p>
Lopp.
</body>