SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2005
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie delete probelm

    i have the following code at the top of each of my web site pages. The probelm im having this as follows:
    1. I sign in successfully
    2. I click the logout image (which should delete the cookie), I am logged out of that page. (when i click refresh, i am still logged out) However, when i click on a link to another page within my web site, I am still logged in.

    Any ideas what could be going wrong. I was told that it could do with something to do with alterations to cookies will only be active on the next page 9(ii.e. after a refresh). However,
    even after a refresh, then clickin on another page of my web site, i will still be logged in. Please Help

    <?
    // Log out image is clicked
    if($_POST['logout_x']>0 || $_POST['logout_y']>0){
    // user has logged out
    unset($_COOKIE['bewiseuser']);
    $logpress = false;
    }

    // Log on image is clicked
    if($_POST['login_x']>0 || $_POST['login_y']>0){

    // Get values of username and password from input boxes
    $logusername = $_POST['logusername'];
    $logpassword = $_POST['logpassword'];

    // encrypt password
    $logpassword = md5($logpassword);

    // if username is not empty, then save cookie
    if ($logusername != ""){
    ob_start();
    $cookie_injection = $logusername.'|'.$logpassword;
    if (setcookie("bewiseuser", $cookie_injection, time()+31536000)) {
    setcookie("bewiseuser", $cookie_injection, time()+31536000, '/');
    }
    else {
    die ("Your browser must support cookies!");
    }
    ob_end_flush();
    }

    $bewiseusername = $logusername;
    $bewisepassword = $logpassword;

    $logpress = true;
    }

    // if cookie already exists, then get values
    if (isset($_COOKIE['bewiseuser'])) {
    $cookie_data = explode("|", $_COOKIE['bewiseuser']);
    $bewiseusername = $cookie_data[0];
    $bewisepassword = $cookie_data[1];
    }
    ?>

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2004
    Location
    3rd rock from the sun
    Posts
    1,005
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try and set the cookie with the same name, but no contents at all.

    ps sanity check, if you are checking cookies on localhost, using IIS on windows you may find it does not behave quite as it should. Not sure if that depends on version of IIS, Browser or what. Make sure you clear your cookies off your hdd.
    isempty()


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •