Reputation:
Hi I have a web in development in a remote server and a problem has come out [I unset the cookies and from that file I can see the cookies unset but in index I see them set again].
My site has the next structure (And im using MVC) I will be as explicit as I can
---public_html
--models
--views
--controllers
--media
--js
--css
--index.php
--.htaccess
--other
.htaccess is set so that: www.eg.eg/?view=lorem --> www.eg.eg/lorem
index calls the views
when a parameter is set eg: www.eg.eg/some
some.php is called from views
STEPS I FOLLOW TO GET THE PROBLEM:
www.eg.eg/login
if cookies are available set cookie named token
www.eg.eg/other/log_out.php
To set cookies I do:
setcookie("sessionPAD", $token, time() + (86400*30), "/", "www.eg.eg", true);
When I write var_dump($_COOKIE)
in index I can see sessionPAD
To log out i do:
<?php
session_start();
if(isset($_SESSION['x']) && isset($_SESSION['y'])){
$x= $_SESSION['x'];
$y= $_SESSION['y'];
require_once '../models/Connection.php';
require_once '../models/User.php';
$User = new User();
$User->deleteToken($selector . $validator);
}
session_destroy();
if (isset($_COOKIE['sessionPAD'])) { //to try to delet cookie
unset($_COOKIE['sessionPAD']);
setcookie("sessionPAD", null, -1, "../");
setcookie("sessionPAD", null, -1, "/");
setcookie("sessionPAD", null, -1);
}
var_dump($_COOKIE); //When I see the result of this sessionPAD is not shown, so I guess session was deleted or can't be seen from that file
//header("location:../"); //line commented to test
After logging out I go to index.php
and guess what, the cookie with the same values is still there.
I have seen code to remove all cookies but I just want to remove that cookie in specific.
Thanks a lot for your time guys
Upvotes: 0
Views: 71
Reputation:
I FOUND THE SOLUTION
Hi guys, after a lot of time trying different options I found out how to remove that cookie
setcookie($name, '', -1, "/", "www.eg.eg", true);
My explanation:
As I'm using SSL I set the cookie to be available in secure connections and also just to be available in my domain, so to unset the cookie I need to specify the same parameters, domain and secure connection only.
After all it wasn't a folder's thing but a parameter's thing
Upvotes: 1