Page 1 of 1
problem with setcookie() (on a WAMP^)
Posted: Wed Mar 31, 2004 4:07 am
by Pozor
Hello,
I try to set a cookie on my local webserver. The function setcookie() returnes TRUE, but no cookie is set. The cookie is sent, but it isn't saved on my HD???
All restriction are set to the minimum in my IE 6.0. (take all cookie)
It works well on my server (inet)...
Infos from phpinfo:
Apache Environment:
HTTP_COOKIE lang=de-iso-8859-1
HTTP Headers Information:
Cookie lang=de-iso-8859-1
session:
session.cookie_domain no value no value
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.use_cookies On On
session.use_only_cookies Off Off
I should mention that i use it for my sessionmanagement, and this doesn't use any session function from PHP. Its based on a DB and works with cookies and url append.
My problem is that i cant write cookies on my local server... WHY???
Somebody has an idea why it doesn't work?
Greez Pozor
PS: the sessionmanagement still works, but only with url append

Posted: Wed Mar 31, 2004 7:24 am
by mudkicker
Does it give any error? (Warning, Fatal error etc.)
Does your session save path set to a existing directory?
Posted: Wed Mar 31, 2004 7:53 am
by Pozor
no,
setcookie returns TRUE, and the md5 hash (doesn't matter how i create this) is written in a db.
the main point is:
Why i cant write a cookie from my local webserver (running on my laptop) at all?
greez Pozor
PS: setcookie() doesnt need a path or someshing else... it just sent header infos to the browser thats it. and the md5 hash is saved in a db as mentioned before...
Posted: Wed Mar 31, 2004 8:03 am
by Zay
when are you checking if it lives?
it does NOT show up on the same pageload...
so:
setcookie(cookiename,"value",time()+3600);
echo $_COOKIE['cookiename'];
won't work.
but:
setcookie(cookiename,"value",time()+3600);
<pageclick>
echo $_COOKIE['cookiename'];
will work...
I once had a problem where it didn't show up after refresh either... it was a wrong setting on php.ini... since I didn't host that site, I don't know which setting that was I'm afraid...
Posted: Wed Mar 31, 2004 8:08 am
by Pozor
Hello,
the problem it won't be set a cookie at all, even if i set it in a script that only contains the setcookie function!
it has nothing to do with refresh or stuff like that, it isn't written to my harddisk at all. This is the real problem. And i haven't a clue why?
greez Pozor
Posted: Wed Mar 31, 2004 8:15 am
by mudkicker
is there any code to show us?
Posted: Wed Mar 31, 2004 8:18 am
by Pozor
hello,
Code: Select all
<?php
$exp = time()+60*60*24*7; //1 Week
$value = $this->sess_id; // is an INT value like 103
$ok = setcookie ("sessid",$value,$exp,"/",$_SERVER['HTTP_HOST']);
?>
greez Pozor
PS: $ok is TRUE
Posted: Wed Mar 31, 2004 11:42 am
by twigletmac
If you're trying to set a cookie for the session, why not just use session_start() and let PHP handle the cookie?
Mac
Posted: Wed Mar 31, 2004 3:03 pm
by Pozor
hello,
because i wanna have the control what the system is doing, and i dont want that php write a file for every session. And i wrote my own sessionmanagement to learn something about PHP.
But that's not the point.
I'm not able to write a cookie on my harddisc, neighter php session function could do this (i think so), when setcookie doesn't work.
setcookie() returns TRUE -> cookie sent, but not saved on my disc...
greez Pozor
Posted: Wed Mar 31, 2004 3:19 pm
by Zay
strange... it seems like you are making no mistakes indeed.... if only I backupped my mail better I might have had the sollution to my problem back then, which seemed the same as yours.
try eliminating all factors...
Code: Select all
<?php
$exp = time()+60*60*24*7; //1 Week
echo $exp."<br>";
$value = $this->sess_id; // is an INT value like 103
echo $value."<br>";
$ok = setcookie ("sessid",$value,$exp,"/",$_SERVER['HTTP_HOST']);
if ($ok) {
echo "return = true";
}
else {
echo "return = false";
}
?>
I think my problem back then was the time being 0. not sure though, but that's my thought atm... if all the vars are filled, I do not know what it could be. please tell me the outcome.
greetz Zay
Posted: Wed Mar 31, 2004 3:52 pm
by Pozor
hello,
i tried this one:
Code: Select all
<?php
$exp = time()+60*60*24*7; //1 Week
$value = 'Testvalue8888888999999'; // sorry usually a md5 hash, but doesn't matter
$ok = setcookie ("sessid",$value,$exp,"/",$_SERVER['HTTP_HOST']);
echo 'Cookie: '.$_COOKIE['sessid'].'<br>';
echo 'Time : '.$exp.'<br>';
echo 'time(): '.time().'<br>';
echo 'Value : '.$value.'<br>';
?>
Code: Select all
Cookie:
Time : 1081374429
time(): 1080769629
Value : Testvalue8888888999999
This is the result after sereval reloads...
no cookie found (always $ok == 1 )??
time seems to be good
greez Pozor