problem with setcookie() (on a WAMP^)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

problem with setcookie() (on a WAMP^)

Post 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 :cry:
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

Does it give any error? (Warning, Fatal error etc.)

Does your session save path set to a existing directory?
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post 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...
Zay
Forum Newbie
Posts: 22
Joined: Tue Mar 23, 2004 3:42 pm

Post 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...
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post 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
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

is there any code to show us?
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post 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
Zay
Forum Newbie
Posts: 22
Joined: Tue Mar 23, 2004 3:42 pm

Post 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
Pozor
Forum Commoner
Posts: 74
Joined: Tue Mar 30, 2004 11:11 pm
Location: Switzerland

Post 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
Post Reply