Click to See Complete Forum and Search --> : setcookie($name, $value, $expires, $this->path, $this->domain, $this->secure);


gert cuykens
02-15-2006, 07:05 AM
<?php

class cookie
{

var $path="/";
var $domain="localhost";
var $secure=0;

function sc($name, $value)
{
$expires = time()+3600;
setcookie($name, $value, $expires, $this->path, $this->domain, $this->secure);
}

}
?>

<?php
include_once("obj/class.cookie.php");
$ck=new cookie();
$ck->sc("servers","asdasdasdasd");
print_r($_COOKIE);
?>

ok why this not working :mad:

Webnerd
02-15-2006, 07:06 AM
Try


<?php
include_once("obj/class.cookie.php");
$ck=new cookie();
$ck->sc("servers","asdasdasdasd");
flush();
print_r($_COOKIE);
?>

bokeh
02-15-2006, 07:12 AM
Because you cannot set and then read a cookie on the same iteration of the script.

Also I just cant see any benefit from this class at all. It seems to me to be extra code just for the hell of it.

SpectreReturns
02-15-2006, 07:25 PM
To be fair, my first class was one which checked to see if emails were valid.

gert cuykens
02-16-2006, 10:55 AM
no flush or refreshing the page doesnt work :mad:

this works doh :confused:

if ($_GET['set'] != 'yes') {

setcookie ('test', 'test', time() + 60);

header ("Location: cookietest.php?set=yes");

} else {

if (!empty($_COOKIE['test'])) {

echo "Cookies are enabled on your browser";

} else {

echo "Cookies are <b>not</b> enabled on your browser";

}

}

I think i will just use the simplified version PS when i https the cookie page wil the cookie be sent encrypted automaticly or do i need to specify the security parameter to 1 seperatly ?

The reason i put it in a class is i finaly understand how it works and now i put everything in classes :D

bokeh
02-16-2006, 11:23 AM
The sixth argument just tells the browser whether (value 0) it may be sent over any type of connection or (value 1) it may only be sent over a secure (SSL) connection. Left unspecified it defaults to value 0. Value 1 does not tell the browser to encrypt the cookie, it just tells it, it may not be sent over an unsecured connection. Anything that passes between the browser and the server over an SSL connection (including cookies, query strings and post requests) is encrypted anyway.

gert cuykens
02-16-2006, 11:40 AM
ok thx