[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 11-04-2007, 03:50 PM   #1 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough


[resolved] ridiculously easy problems, but they have me stumped (cookies)

ok, im an idiot, simple things stump me.

for instance, this beauty!

1. I can't display/access cookies. I can make them, see them if I browse to the file, but when I use:

Code:
        echo $_COOKIE['siteLogin'];
	if (isset($_COOKIE['test'])){
		echo "worky";
	}else{
		echo "no cookie here";
	}
I get nothing, no output (names of cookies are correct). to make them I use:

Code:
@setcookie('siteLogin', $cookie, time() + 31104000);
			@setcookie("test", "lol", time() + 36000);

any ideas, its driving me crazy

Last edited by Albino; 11-12-2007 at 02:44 PM.
Albino is offline  
Old 11-04-2007, 04:07 PM   #2 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services

 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Remove '@' from the function call, see if you get any errors.
__________________
Eric is offline  
Old 11-05-2007, 01:34 AM   #3 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough


sorry I should have said, I've already tried that, no errors
Albino is offline  
Old 11-05-2007, 04:49 AM   #4 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Are you setting the cookie in the same page call as when you are checking its existence. A cookie is not available until a page after you created it.

Ie if you create the cookie on login.php and then immediately try to check its existence it will not work. The cookie will not be available until they go to another page. The best way to get around this if it is the case if use a header redirect once the cookie is set.

Also when you are testing have the following at the top of your scripts:-

PHP Code:
error_reporting(E_ALL);
Although @ does indeed suppress errors, the errors still may not show depending on your servers configuration.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft

Last edited by peter@flexiwebhost; 11-05-2007 at 04:57 AM.
Peter is offline  
Old 11-05-2007, 06:43 AM   #5 (permalink)
Senior Member
 
Join Date: Aug 2007
Posts: 2,167
457.00 NP$ (Donate)

jido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond repute


Check in your browser (Security/Show cookies or Cookie Manager).

Which domain is it set for? What is the expiry time? What is the time on your web server and on your computer?
__________________
______________________________________
Time After Leisure & Events discussions
eBay auction aqnu, pzpy, vqqr.com 16 llll.com start $.95
_______________ f o r . s a l e ______________
jido is offline  
Old 11-05-2007, 12:01 PM   #6 (permalink)
Danltn.com
 
Daniel's Avatar
 
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
13.51 NP$ (Donate)

Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute

Ethan Allen Fund Ethan Allen Fund
I tried some quick code and it worked fine for me.

PHP Code:
<?php

  error_reporting
(E_ALL);
  
$cookie = "Wee"; // Well it needs a value...
  
  
if(isset($_GET['del'])) {
  
setcookie('siteLogin', "", time() - 31104000);
  
setcookie("test", "", time() - 36000);
  echo
"Deleted cookies. Refresh for it to work!";
  exit();
  }

    
setcookie('siteLogin', $cookie, time() + 31104000);
  
    if (isset(
$_COOKIE['test']))
    {
            echo
"Working<br />";
    }
    else
    {
        if(
setcookie("test", "lol", time() + 36000)) echo "I think we made one...<br />";
        echo
"Not working<br />"; // Echo after to ensure you don't get Header problems
        
echo "<br />Try refreshing your browser, browsers normally need a refresh to get it to work";
    }
    
    if(isset(
$_COOKIE['siteLogin'])) echo $_COOKIE['siteLogin'];
    
?>
Daniel is offline  
Old 11-07-2007, 03:39 AM   #7 (permalink)
New Member
 
Join Date: Nov 2005
Posts: 6
0.00 NP$ (Donate)

LovesYou is an unknown quantity at this point


Quote:
Originally Posted by Danltn
I tried some quick code and it worked fine for me.

PHP Code:
<?php

  error_reporting
(E_ALL);
  
$cookie = "Wee"; // Well it needs a value...
  
  
if(isset($_GET['del'])) {
  
setcookie('siteLogin', "", time() - 31104000);
  
setcookie("test", "", time() - 36000);
  echo
"Deleted cookies. Refresh for it to work!";
  exit();
  }

    
setcookie('siteLogin', $cookie, time() + 31104000);
  
    if (isset(
$_COOKIE['test']))
    {
            echo
"Working<br />";
    }
    else
    {
        if(
setcookie("test", "lol", time() + 36000)) echo "I think we made one...<br />";
        echo
"Not working<br />"; // Echo after to ensure you don't get Header problems
        
echo "<br />Try refreshing your browser, browsers normally need a refresh to get it to work";
    }
    
    if(isset(
$_COOKIE['siteLogin'])) echo $_COOKIE['siteLogin'];
    
?>
Great Bit of code.. will help me with a problem I've been having Thanks.
LovesYou is offline  
Old 11-07-2007, 08:07 AM   #8 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough


ok, thanks everyone for the help so far! (ive repped you all).

Danltn, that code works fine for me but when I intergrate it, it still does't work. Does where you declare the cookie matter?

like say I make the cookie from scripts/php/login.php, but then wanted to check it from root, would that matter?

I don;t see why it should, but its the only thing I can think of
Albino is offline  
Old 11-07-2007, 08:16 AM   #9 (permalink)
Senior Member
 
Join Date: Aug 2007
Posts: 2,167
457.00 NP$ (Donate)

jido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond reputejido has a reputation beyond repute


Quote:
Originally Posted by Albino
like say I make the cookie from scripts/php/login.php, but then wanted to check it from root, would that matter?
It would not matter as long as they are the same domain (eg. uploads.mydomain.com)

Did you check the cookie in the browser as I advised? The cookies will not be set if there is some output before the cookie code, see the setcookie documentation. I think even a blank line can prevent the cookie from being set.
__________________
______________________________________
Time After Leisure & Events discussions
eBay auction aqnu, pzpy, vqqr.com 16 llll.com start $.95
_______________ f o r . s a l e ______________
jido is offline  
Old 11-07-2007, 08:26 AM   #10 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough


yea, I checked the cookie, via the tools->options->privacy->show cookies method in firefox. They show up and I can see the value is what I want them to be.

this really has me stumped!
Albino is offline  
Old 11-07-2007, 08:43 AM   #11 (permalink)
Danltn.com
 
Daniel's Avatar
 
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
13.51 NP$ (Donate)

Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute

Ethan Allen Fund Ethan Allen Fund
It sometimes complains if the cookie is accessed from a different directory to the one it was set in.

E.G. I might not be able to access my cookie "EG" from /danswork/ when I set it in /danscode/.

Dan
Daniel is offline  
Old 11-07-2007, 08:53 AM   #12 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough


ok, so looks like it might be that then.
Albino is offline  
Old 11-07-2007, 05:30 PM   #13 (permalink)
NamePros Member
 
Join Date: May 2006
Posts: 160
81.00 NP$ (Donate)

TwistMyArm is on a distinguished road


As per http://ca3.php.net/setcookie , the default path for the cookie is the current directory. You want to override that with a '/'. ie. if you give a 4th parameter to your setcookie function call and that 4th parameter is '/', you shouldn't have any problems with that.
TwistMyArm is offline  
Old 11-12-2007, 02:44 PM   #14 (permalink)
Munky Designs
 
Join Date: May 2005
Posts: 997
417.00 NP$ (Donate)

Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough


cheers TMA, it worked great
Albino is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:19 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85