(localhost) cookie weirdness

This is a discussion on "(localhost) cookie weirdness" within the PHP Forum section. This forum, and the thread "(localhost) cookie weirdness are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 28th, 2007, 16:30
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 233
Thanks: 4
Thanked 0 Times in 0 Posts
(localhost) cookie weirdness

I do my development and testing in a Xampp environment, running all the code on the localhost. But for some reason, I seem to be unable to set cookies in that environment. When I look at cookies for 127.0.0.1, there are cookies there (that were set by other pages that I didn't write), so (I think) I know they can be set... I don't know what I'm doing wrong!

Here's a simple cookietest page I did...
PHP: Select all

<?php
if (isset($_POST['initials']) && isset($_POST['zipcode'])) {
    
setcookie('initials'$_POST['initials'], time()+(180*24*3600));
    
setcookie('zipcode'$_POST['zipcode'], time()+(180*24*3600));
    
$redirect="cookietest2.php";
    
header("Location: $redirect");
} else {
    echo 
"
<form action='{$_SERVER['PHP_SELF']}' method='POST'>
<p>Please type your initials: <input type='text' name='initials' /></p>
<p>Please enter your zipcode? <input type='text' name='zipcode' /></p>
<p><input type='submit' /></p>
</form>
"
;
}
?>
And here's the page it redirects to.
PHP: Select all

<?php
if (isset($_COOKIE['initials'])) {
    echo 
"You've got cookies!<br />The initials cookie 
             is set to "
.$_COOKIE['initials']."<br />";
} else {
    echo 
"Your browser did not accept the initials cookie.<br />";
}
if (isset(
$_COOKIE['zipcode'])) {
    echo 
"You've got cookies!<br />The zipcode cookie 
             is set to "
.$_COOKIE['zipcode']."<br />";
} else {
    echo 
"Your browser did not accept the zipcode cookie.<br />";
}
?>
This fails to set cookies and returns the "Your browser did not accept" messages.

I can create cookies in a text file and import them (using CookieSafe) and then I can read them (not sure if I can write/update them) but if I need to set a cookie dynamically (e.g. the session ID), I can't do it.

Update - I just tested and I can NOT update cookies set by importing via CookieSafe. That makes these cookies pretty useless.

Last edited by Donny Bahama; May 28th, 2007 at 16:46.
Reply With Quote

  #2 (permalink)  
Old May 29th, 2007, 01:58
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: (localhost) cookie weirdness

I'm sorry mate, I can't help you on this one.
But I can tell you that either:
a) You logic is wrong, you're not actually setting the cookies.
b) The security settings on your browser don't allow cookies (unlikely)
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #3 (permalink)  
Old May 29th, 2007, 04:26
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 233
Thanks: 4
Thanked 0 Times in 0 Posts
Re: (localhost) cookie weirdness

No. I'm not setting cookies. I know that. (And that's the problem.) The same page, posted to a (remote) web server sets cookies just fine.

Thanks for looking in, Diego.
Reply With Quote
  #4 (permalink)  
Old May 29th, 2007, 13:17
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: (localhost) cookie weirdness

Can't tell you what's wrong but the first thing I'd do is try echoing the POST variables right after the php tag to make sure they're okay and see if it's doing anything weird to the values.

Second thing I'd try is setting the POST variable values to a simple variable then play with quotes around them inside the cookie parameters.

Might also take out or simplify the time variable until the first two parameters succeed in setting a cookie.
Reply With Quote
  #5 (permalink)  
Old May 29th, 2007, 14:44
Reputable Member
Join Date: Mar 2005
Location: Margaritaville (a state of mind somewhere between Inebriation and San Diego), CA
Posts: 233
Thanks: 4
Thanked 0 Times in 0 Posts
Re: (localhost) cookie weirdness

Good suggestions, all, Mason. Thanks. I'll give that a try.
Reply With Quote
Reply

Tags
localhost cookies xampp

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Fortune Cookie alexgeek Webforumz Cafe 7 Oct 11th, 2007 13:13
Cookie Help! graeme JavaScript Forum 3 Jun 17th, 2006 14:22
Cookie Data thoulden Classic ASP 2 Aug 23rd, 2005 12:02


All times are GMT. The time now is 11:46.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43