# Solved: setcookie in xampp



## JiminSA (Dec 15, 2011)

I've just written a little ticketing system and decided to optionally allow the user to remain logged in to it and use the following code to facilitate this

```
setcookie('username', $_POST['username'], time()+60*60*24*365, '/account', 'http://localhost/Shelton');
					setcookie('password', md5($_POST['password']), time()+60*60*24*365, '/account', 'http://localhost/Shelton');
```
I'm testing in xampp and hope I have the above urls correct
Unfortunately, when the user gets out of the browser and then returns, I am not picking up the cookies set in the code above, by using the following test

```
if (isset($_COOKIE['username']) && isset($_COOKIE['password'])) 
{
	$_SESSION['ticket_login'] = true;
 	$_SESSION['username'] = $_COOKIE["username"];
	$err = false;
	$msg = 'Welcome back ' . $_COOKIE["username"];
}
```
Once again it's a question of my not being able to see the wood for the trees can anyone put me out of my misery?


----------



## allnodcoms (Jun 30, 2007)

Morning Jim!

Try it without the path and URL parameters, PHP will do the leg work on those. Apart from that, all looks well.
I'd also go into your browser settings and confirm that the cookie is actually being written, but I think it's a domain thing...

Dan


----------



## JiminSA (Dec 15, 2011)

Gee-Willickers Danny, I've missed your erstwhile erudition. Cookies are now hot and fresh from the oven - thanks Chomma


----------



## allnodcoms (Jun 30, 2007)

JiminSA said:


> erstwhile erudition.


Wow, I've not been accused of that since the "Supermarket Incident" of '97... 

Danny


----------



## JiminSA (Dec 15, 2011)

Just to close off this post I discovered this nice little trick to delete a cookie ...

```
setcookie('username', $_SESSION['username'], 1);
	setcookie('password', $_SESSION['password'], 1);
```
... which you can utilise if the user wants to log out of his year long stay


----------

