karq Posted August 8, 2008 Share Posted August 8, 2008 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 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 More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 You don't need to use session_register or session_is_registered anymore. It's deprecated. Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611627 Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 <?php if ($_GET['act']=='logout') { $_SESSION['logged']=array(); header("Location: /index.html"); } ?> Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611632 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 You probably also want session_destroy(). Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611637 Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 I don't see a reason to use session_destroy() if you are just wanting to log the user out. Sometimes the remaining session vars are useful, and only logged needs to be unset. Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611647 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 In that case, you need to specifically know which ones you want to destroy. And if you rework your login system, you may need to heavily rework your logout system, etc. Kind of annoying. ._. Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611653 Share on other sites More sharing options...
Jabop Posted August 8, 2008 Share Posted August 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611680 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 I know, but if you decided to change an aspect of your login system, you'd need to rework your logouts too. This is neither here nor there and it's just a preference. Whatever. =P Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611686 Share on other sites More sharing options...
karq Posted August 8, 2008 Author Share Posted August 8, 2008 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>"; } ?> Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611773 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 You tell us. Does it throw an error or anything? Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611799 Share on other sites More sharing options...
karq Posted August 8, 2008 Author Share Posted August 8, 2008 Yes it does Parse error: syntax error, unexpected T_ELSE in /sees.php on line 32 Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611806 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Which if did you want that else to be a part of? Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611810 Share on other sites More sharing options...
karq Posted August 8, 2008 Author Share Posted August 8, 2008 Which if did you want that else to be a part of? Thanks for the hint, got it working Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611839 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Yeah, I didn't want to give the answer away that easily. xD You had } }, thereby closing both ifs. xD Link to comment https://forums.phpfreaks.com/topic/118792-how-to-make-logout-link/#findComment-611841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.