#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Ithaca
    Posts
    68
    Rep Power
    3

    How to set and unset cookie for a site with url rewrite?


    Well on my site the url rewrite has been working like a charm, but right now I am encountering a big problem. I am unable to log out after logging in, which never happened before with the old system. The url for login and logout looks like these:

    PHP Code:
    www.domain.com/scriptpath/login
    www
    .domain.com/scriptpath/login/logout 
    So yeah, both of them are in the same script file/controller. Login is the default/index action, while logout is a secondary operation.

    The problem is that when I unset cookies with setcookie("cookie", "", time() - 3600), it only unset cookies for the pseudo-directory /login, but not for the entire domain and scriptpath. For this reason I appear to be logged out while visiting the login/logout page, but at anywhere else I am still logged in. There's nothing I can do about it...

    So anyone of you familiar with url rewrite? Can you please help me fix this weird issue? And if I may ask, what do you do with your own login/logout system under url rewrite?
  2. #2
  3. Jealous Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,302
    Rep Power
    9400
    So why can't you set the path in the call to setcookie()?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Ithaca
    Posts
    68
    Rep Power
    3
    Thanks for the reply, and well actually I sorta fixed the problem by inserting $_SERVER['HTTP_HOST']. The only remaining issue is that it may end up clearing cookies for all subdomains, so I wonder if there's a way to specify one particular subdomain.
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Yes, there is. Specify the domain. I'm not sure what the question even is. There's a variable for host. Use that.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo