| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Munky Designs Join Date: May 2005
Posts: 996
![]() ![]() ![]() | [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: ????: NamePros.com http://www.namepros.com/programming/392179-ridiculously-easy-problems-but-they-have.html Code: echo $_COOKIE['siteLogin'];
if (isset($_COOKIE['test'])){
echo "worky";
}else{
echo "no cookie here";
} Code: @setcookie('siteLogin', $cookie, time() + 31104000);
@setcookie("test", "lol", time() + 36000); any ideas, its driving me crazy
__________________ Toddish.co.uk - Portfolio/Blog Powcomics.com - Webcomic Hosting/Directory Erant.co.uk - vent your rage!
Last edited by Albino; 11-12-2007 at 03:44 PM.
|
| |
| | #4 (permalink) |
| NamePros Expert Join Date: Nov 2003 Location: Scotland
Posts: 5,069
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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. ????: NamePros.com http://www.namepros.com/showthread.php?t=392179 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:
__________________ 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 05:57 AM.
|
| |
| | #5 (permalink) |
| Senior Member Join Date: Aug 2007
Posts: 2,172
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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?
__________________ ______________________________________ Help with crosswords http://lettercombination.com Pitfalls of Java http://javasyntax.com _______________ f o r . s a l e ______________ |
| |
| | #6 (permalink) |
| Danltn.com Join Date: May 2007 Location: Danltn.com / Nottingham, UK
Posts: 1,201
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | I tried some quick code and it worked fine for me. PHP Code:
__________________ |
| |
| | #7 (permalink) | ||||
| New Member Join Date: Nov 2005
Posts: 6
![]() |
Thanks. | ||||
| |
| | THREAD STARTER #8 (permalink) |
| Munky Designs Join Date: May 2005
Posts: 996
![]() ![]() ![]() | 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 |
| |
| | #9 (permalink) | ||||
| Senior Member Join Date: Aug 2007
Posts: 2,172
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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.
__________________ ______________________________________ Help with crosswords http://lettercombination.com Pitfalls of Java http://javasyntax.com _______________ f o r . s a l e ______________ | ||||
| |
| | #11 (permalink) |
| Danltn.com Join Date: May 2007 Location: Danltn.com / Nottingham, UK
Posts: 1,201
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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
__________________ |
| |
| | #13 (permalink) |
| NamePros Member Join Date: May 2006
Posts: 160
![]() | 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. |
| |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| |