Irish SEO,  Marketing & Webmaster Discussion

 

Sessions and logging out with mdb2

This is a discussion on Sessions and logging out with mdb2 within the Coding Help forums, part of the Webmaster Help category; Hi all.... I have code here that allows me to login to an area of a site but loggin out ...


Go Back   Irish SEO, Marketing & Webmaster Discussion > Webmaster Help > Coding Help

Register Forum Rules FAQDonate Members List Calendar Search Today's Posts Mark Forums Read


Notices

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 14-01-2008, 04:11 PM
Joseph Grogan's Avatar
Wannabe Geek
 
Join Date: Jul 2007
Location: Bogland, beside birr...Cloghan
Posts: 147
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Joseph Grogan will become famous soon enough
Send a message via Skype™ to Joseph Grogan
Default Sessions and logging out with mdb2

Hi all....
I have code here that allows me to login to an area of a site but loggin out you have to close down the browser and i dont want that i want a logout page.

Here is the code i using to log in

PHP Code:
<?php
session_start
();
require_once(
'***login page details****');
require_once(
'***Where Pear MDB2 is located****');;
if (empty(
$_SESSION['user_id'])) {

    if (!isset(
$_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
        
header('WWW-Authenticate: Basic realm="Member Area"');
        
header("HTTP/1.0 401 Unauthorized");
        echo 
"You must enter in a username and password combination!";
        exit;
    }
    
    
$connection MDB2::connect("mysql://$db_username:$db_password@$db_host/$db_database");

    if (
MDB2::isError($connection)){
        die (
"Could not connect to the database: <br />"MDB2::errorMessage($connection));
    }
    
    
$username mysql_real_escape_string($_SERVER['PHP_AUTH_USER']);
    
$password mysql_real_escape_string($_SERVER['PHP_AUTH_PW']);
    
$query "SELECT `user_id`, `username` FROM `users` WHERE
`username`='"
.$username."' AND `password`=MD5('".$password."') LIMIT 1";
    
$result $connection->query($query);
    
    if(!(
$row $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
        
header('WWW-Authenticate: Basic realm="Member Area"');
        
header("HTTP/1.0 401 Unauthorized");
        echo 
"Your username and password combination was incorrect!";
        exit;
    }
    
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['username'] = $row['username'];
}
This works fine its just logging out wont work.. I have a page called logout.php

PHP Code:
session_start();
session_destroy();
$_SESSION = array();
echo 
"Thank you for loggin out: "
But this does not remove any details as when i go back to the login page all my information is still there...

Last edited by Joseph Grogan; 14-01-2008 at 04:14 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 14-01-2008, 06:00 PM
louie's Avatar
Senior Member
 
Join Date: Jan 2006
Location: Dublin, Ireland
Posts: 2,007
Nominated 5 Times in 3 Posts
TOTW/F/M Award(s): 0
louie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud oflouie has much to be proud of
Send a message via Yahoo to louie Send a message via Skype™ to louie
Default

did you try unset?
PHP Code:
 
unset($_SESSION['user_id']);
unset(
$_SESSION['username']); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 15-01-2008, 03:03 PM
Joseph Grogan's Avatar
Wannabe Geek
 
Join Date: Jul 2007
Location: Bogland, beside birr...Cloghan
Posts: 147
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Joseph Grogan will become famous soon enough
Send a message via Skype™ to Joseph Grogan
Default

Hi louie. No that is not working either. Cant seem to figure it out.

Ok I have my session start in a file called authenticate.php and that is used on everypage of the directory so no page can be seen without a password. But do i need that authenticate.php page on the logout page so the session info can be unset do i just have the code you cave me by itself. Not really sure on what to do with it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
logging, mdb2, sessions

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 09:17 PM.


Powered by: vBulletin Version 3.7.3, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
Hosted in Ireland by Blacknight - Test your ISP |Irish Hosting Directory| Armchair.ie|Logo by Eden Web Design|Avatars by Afterglow |Latest Blog Entries | VPS HostingAd Management by RedTyger

Search Engine Friendly URLs by vBSEO 3.2.0