Jump to content

how to make logout link


karq

Recommended Posts

can someone tell me how to make a logout link?

i'm a noob and my code maybe s*it but it works for me :D

my page code:

<?php
session_start();
$kasutaja=$_POST["kasutaja"];
$parool=$_POST["parool"];
$ava=fopen("kasu.txt","r");
$ava2=fopen("parol.txt","r");
$kasu=fread($ava,100);
$parol=fread($ava2,100);
if (session_is_registered("ses")) {
echo "<zen href=>Logi Välja</a><br />";
echo "<center><b>Tere Tulemast " . $kasutaja . "</b>";
echo "<br /> <form action='salv.php' method='POST' >
<textarea rows='20' cols='30' name='uudis'>";
include 'uudis.txt';
echo "</textarea> <br />";
echo "<input type='submit' value='Salvesta' />";
echo "</center>";
}

else {
if ($kasutaja==$kasu && $parool==$parol) {
$_SESSION["sees"]=$kasutaja==$kasu && $parool==$parol;
session_register("ses");
echo "<center><b>Tere Tulemast " . $kasutaja . "</b>";
echo "<br /> <form action='salv.php' method='POST' >
<textarea rows='20' cols='30' name='uudis'>";
include 'uudis.txt';
echo "</textarea> <br />";
echo "<input type='submit' value='Salvesta' />";
echo "</center>";

}
else {
session_destroy();
echo "Proovi uuesti!";
}
}
?>

Link to comment
https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/
Share on other sites

I don't see what you're trying to get across with what you just said?

 

<?php

// user login is successful, set up the session
$_SESSION['logged']['user']=$Person;

// example of someone trying to do something that requires being logged in

if ($_SESSION['logged']) {
     // do stuff that would be permissible
     // in this case, it is, cause the login was just successful
} else {
     $Err='You need to login to do that';
}
?>

 

I know you know how that code works, I don't have to explain. I just wanted to give you some type of structure to look at to see what I'm saying. There is no reason to completely destroy a session upon logging out. Ever. You simply should set $_SESSION['logged'] back to a blank array, thus saving all of your session info that isn't pertaining to the login system.

ok  I sorted that logout link thing out, but now I have another problem, why can I use that last else?

<?php
session_start();
$kasutaja=$_POST["kasutaja"];
$parool=$_POST["parool"];
$ava=fopen("kasu.txt","r");
$ava2=fopen("parol.txt","r");
$kasu=fread($ava,100);
$parol=fread($ava2,100);
if (!isset($_SESSION["sees"])) {
if ($kasutaja==$kasu && $parool==$parol) {
$_SESSION["sees"];
echo "<a href='out.php'>Logi välja</a>";
echo "<center><b>Tere Tulemast " . $kasutaja . "</b>";
echo "<br /> <form action='salv.php' method='POST' >
<textarea rows='20' cols='30' name='uudis'>";
include 'uudis.txt';
echo "</textarea> <br />";
echo "<input type='submit' value='Salvesta' />";
echo "</center>";
}
}
else {
echo "<a href='out.php'>Logi välja</a>";
echo "<center><b>Tere Tulemast " . $kasutaja . "</b>";
echo "<br /> <form action='salv.php' method='POST' >
<textarea rows='20' cols='30' name='uudis'>";
include 'uudis.txt';
echo "</textarea> <br />";
echo "<input type='submit' value='Salvesta' />";
echo "</center>";
}
else { <----- This else I mean!!!!
echo "Proovi uuesti<br />";
echo "<a href='logi.php'>Tagasi</a>";
}


?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.