| |||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | #1 (permalink) |
| Munky Designs | [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";
}
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. |
| |
| | #4 (permalink) |
| Senior Member | 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:
__________________ 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. |
| |
| | #5 (permalink) |
| Senior Member | 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 |
| |
| | #6 (permalink) |
| Danltn.com | I tried some quick code and it worked fine for me. PHP Code: |
| |
| | #7 (permalink) | |
| New Member | Quote:
Thanks. | |
| |
| | #8 (permalink) |
| Munky Designs | 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 | Quote:
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 | |
| |
| | #13 (permalink) |
| NamePros Member | 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 | |
| |