Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Unable To Remove Cookies in codeigniter

Posted on 2010-11-28
5
Medium Priority
?
3,291 Views
Last Modified: 2012-08-13
dear

problem is this :

when i am not able to reset cookies but there's two ways one way i can do but another way i cannot.

1. i place one link as domain.com/user/logout

when user click on this then i place code

$this->session>un_set('user_id');
delete_cookie('user_id');
redirect('domain.com','refresh');

in this user redirect to this link then move to domain.com but again user login in..

2. when i call domain.com/user/logout from address bar then it do same function but this do all things as per requirement unset session and delete cookies and user logout.

so please let me know why this happen.. i need when user click on logout button then all done.

Thanks
0
Comment
Question by:activesoftware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 34231520
All instances of a browser share the same cookie jar.  So if you test with more than one window open you will get strange results.  Try closing all your browsers, then opening one and only one window to the app and trying it again.

Not specific to codeigniter, but here is a sample logout script.  Read it over - code and comments, and let me know if there is anything you do not understand.

Best, ~Ray
<?php // RAY_logout_example.php
error_reporting(E_ALL);

// MAN PAGE HERE: http://us.php.net/manual/en/book.session.php
// ALWAYS START THE SESSION ON EVERY PAGE
session_start();

// SEE IF THE CLIENT IS ALREADY LOGGED OUT
if (empty($_SESSION["uid"]))
{
    echo "<br/>YOU ARE NOT LOGGED IN \n";
    echo "<br/>CLICK HERE TO <a href=\"RAY_login_example.php\">LOG IN</a>\n";
    die();
}

// SET THE EXPIRATION FOR COOKIES
$cookie_expires	= time() - date('Z') - 60*60*24; // A 24-HOUR DAY IN SECONDS ( = 86,400 )

// CLEAR THE INFORMATION FROM THE $_SESSION ARRAY
$_SESSION = array();

// IF THE SESSION IS KEPT IN COOKIE, FORCE SESSION COOKIE TO EXPIRE
if (isset($_COOKIE[session_name()]))
{
    setcookie(session_name(), NULL, $cookie_expires, '/');
}

// TELL PHP TO ELIMINATE THE SESSION
session_destroy();


// OPTIONAL - CLEAR ALL COOKIES
// foreach ($_COOKIE as $key => $value)
// {
//    setcookie($key, NULL, $cookie_expires, '/');
// }

// OPTIONAL - REDIRECT TO THE HOME PAGE
// header("Location: /");
// exit;


// GIVE THE CLIENT A LINK TO THE LOGIN
echo "<br/>YOU ARE LOGGED OUT\n";
echo "<br/>CLICK HERE TO <a href=\"RAY_login_example.php\">LOG IN</a>\n";

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34273641
I object to deleting this question -- it's one that seems to appear a lot, and we should have good answers for it in the EE data base.  

If my response was not helpful, you should post back with a question to clarify.  If my response was helpful, you should award the points.  If you found a completely different answer from a separate source you should post that answer with a code sample to illustrate it, and accept it as the solution.  

Thanks, ~Ray
0
 

Expert Comment

by:_alias99
ID: 34367472
Starting the auto-close procedure on behalf of the question asker.

_alias99
Community Support Moderator
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question