SitePoint Sponsor |
|
User Tag List
Results 1 to 8 of 8
Thread: logging out
-
Nov 7, 2008, 04:59 #1
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
logging out
Hi,
How would i place the log out link in every pages just when the user has logged in?
-
Nov 7, 2008, 05:24 #2
- Join Date
- Oct 2008
- Location
- London
- Posts
- 862
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Pawel Decowski (you should follow me on Twitter)
-
Nov 7, 2008, 05:27 #3
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
There is session variable.
I know the logic of doing this, just the actual technique is unknown.
-
Nov 7, 2008, 05:43 #4
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
Sure, something like this should do it.
PHP Code://--> Anywhere on page.
<?php
session_start();
if($_SESSION['auth']['loggedIn'] == true){
echo '<a href="http://www.yourserver.com/logOut.php" title="Log Out">Log Out</a>';
}
?>
//--> logOut.php
<?php
session_start();
if(isset($_SESSION['auth']))
{
unset($_SESSION['auth']);
}
header('Location: http://www.yourserver.com/');
exit;
?>@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
-
Nov 7, 2008, 06:10 #5
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
what about logout link? I need the link to be available in every pages.
This probably involves some css, isn't it ?
Further more, I need the link to disappear as long as user logged out
-
Nov 7, 2008, 06:17 #6
- Join Date
- Apr 2008
- Location
- North-East, UK.
- Posts
- 6,111
- Mentioned
- 3 Post(s)
- Tagged
- 0 Thread(s)
The logout link will only show if the user is logged in, just place the top bit of code on each page/template you want the logout link to be displayed.
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.
-
Nov 7, 2008, 10:43 #7
- Join Date
- Oct 2008
- Posts
- 295
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am not sure if this is anymore any help but ill post it anyway in case op wanted to see how the link is handled using eg. GET method.
PHP Code:// The link and when clicked it will set variable called $_GET['logout']
echo '<a href="http://www.yourserver.com/'. $_SERVER['SCRIPT_NAME'] .'?logout">Logout</a>';
// And then you check if $_GET['logout'] is set or not and if yes you set your
// logout/auth variable to something that you use to check if user is logged or not.
if (isset($_GET['logout']))
{
$_SESSION['logged'] = false;
}
-
Nov 7, 2008, 11:02 #8
- Join Date
- Sep 2008
- Location
- Dubai
- Posts
- 971
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks