Cookies, and my stomack hurts

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Cookies, and my stomack hurts

Post by Calimero »

I wanted php to put a cookie to the user that verify's on the log-in script, but .... something I don't obviously do as I should.

PHP net, Zend, .... Doc's looked at - still no idea whats wrong.

I need the following to be executed:

page1.php
- has a form
- form is submitted by POST to page2.php


page2.php
- has to take the data and create variables
- connect to mysql DB and perform a query
- check if mysql_num_rows == 1
- create a variable $result1 - that contains $username, $password, $id of the user
- to SETCOOKIE with the permision to be visible in all directories on only my site ( currently it's tested on the localhost )
- to forward the user ( Header() method ) back to the page which the user tried to access


NOW all of this I built and it works pefectly - exept that my blasted computer does not create a cookie. One of the following occurs:
- Cookie ( value ) doesn't shows anywhere
- Sometimes ( randomly ) it can show, but only if I don't put anything for the directory and domain ( to lock the cookie to it ) and then I can access it only in that folder ( as the cookie default )

Here is my cookie code:

Code: Select all

$value = "some usernames, passwords and id's delimited by a comma";
setcookie("nice-cake", $value, time(), "/", "localhost");
NOTE: for apache - my site is called 1.seton.biz, so I tried using ".seton.biz" instead of "localhost" - doesn't do anything.

Also - how do I check for physical existence of the cookie - read something that cookie may not report error, but also might not be sent to the user.

Can anyone help me with this stup.. problem.
Greatly appreciated.

Testing machine spec's:
OS: WinXP
Server: Apache 1.29.xx
PHP: with Zend enabler - I think 4.xx - something
DB: MySQL 4.1.11

And because of the Zend software I can't find php.ini anywhere on my computer, anyone has a solution to this one !?!?
Black Unicorn
Forum Commoner
Posts: 48
Joined: Mon Jun 16, 2003 9:19 am
Location: United Kingdom

Cookies

Post by Black Unicorn »

Your cookie expires the moment you set it.

Use time()+$secs*$mins*$hrs or some fixed, big, number.
Best luck,

H
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

Post by Calimero »

parameter time() should ( as I understood ) expire cookie once the browser is closed, so until I'm on the website and not closing the browser - the cookie is alive !?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Calimero wrote:parameter time() should ( as I understood ) expire cookie once the browser is closed, so until I'm on the website and not closing the browser - the cookie is alive !?
Nearly correct.

I think if you want the cookie to last the length of the session....just dont set any time parameter
User avatar
Calimero
Forum Contributor
Posts: 310
Joined: Thu Jan 22, 2004 6:54 pm
Location: Milky Way

...

Post by Calimero »

Progress made:

changed time() to (int) 0, and now the cookie works, thanks Black Unicorn


still having problems with domain locking - curretly I'm testing the site on the localhost machine, which is also called 1.mysite.biz - can someone shead some lite to me on this ?!?!?!

Does this works ( in theory in localhost debugging ) or only in real-life internet space ?!?


Thanks, for so far, and ahead !
Post Reply