ed
Member
Registered: 10th Sep 03
User status: Offline
|
Decided to have another go at cookies but they just don't work at all for me 
On one page I have this section of script:
code:
case 1:
$target="../index.php";
setcookie("user", "$userID", time()+3600);
setcookie("pass", "$checkPass", time()+3600);
include('forward.php');
break;
Which works as I can see the set cookie in Firefox... But on the next page I have this to start with to check and make sure it works:
code:
$user=$_COOKIE["user"];
$pass=$_COOKIE["pass"];
echo $user;
echo $pass;
Of which I am not getting output from at all.
Would the fact that I am locally testing this script using Vertrigoserv cause any problems? I have read so many things on the web and I can't seem to find the problem
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
how does it know what cookie its looking for?
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
Surely $_COOKIE["pass"]; is telling it to look for the cookie that was set using setcookie("pass", "$checkPass", time()+3600);?
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
what happens if you do
print_r($_COOKIE);
|
Richie
Member
Registered: 3rd Dec 02
Location: Newport, Wales
User status: Offline
|
http://www.cookiecentral.com/
|
_Allan_
Member
Registered: 24th Mar 04
User status: Offline
|
mmm subway cookies, 3 for £1.
|
Ash_EP3
Member
Registered: 15th May 07
Location: Melksham, Wiltshire
User status: Offline
|
quote: Originally posted by _Allan_
mmm subway cookies, 3 for £1.
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
quote: Originally posted by Steve
what happens if you do
print_r($_COOKIE);
Returns Array()
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
Do you need to use the cookie equivalent of session_start(); ?
[Edited on 13-11-2007 by Laney]
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
id say its your server or browser privacy settings
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
I finally figured it out, it's been pissing me off for ages. Basically I needed to set the default domain for where the cookie is available by doing this:
setcookie("user", "$userID", time()+3600, "/");
That makes the cookie available for the whole site which is what I need because I have everything neatly stored in folders for easy human access...
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
aye, thought it was something to do with it not knowing where the cookie was
|
Laney
Member
Registered: 6th May 03
Location: Leeds
User status: Offline
|
quote: Originally posted by ed
I finally figured it out, it's been pissing me off for ages. Basically I needed to set the default domain for where the cookie is available by doing this:
setcookie("user", "$userID", time()+3600, "/");
That makes the cookie available for the whole site which is what I need because I have everything neatly stored in folders for easy human access...
So "/" stopped it working?
Typical
|
Steve
Premium Member
Registered: 30th Mar 02
Location: Worcestershire Drives: Defender
User status: Offline
|
no that just means it looks for anything after the domain name
[Edited on 13-11-2007 by Steve]
|