Page 1 of 1

Cookies, and my stomack hurts

Posted: Wed May 25, 2005 2:26 am
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 !?!?

Cookies

Posted: Wed May 25, 2005 3:31 am
by Black Unicorn
Your cookie expires the moment you set it.

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

H

Posted: Wed May 25, 2005 4:59 am
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 !?

Posted: Wed May 25, 2005 5:01 am
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

...

Posted: Wed May 25, 2005 7:24 am
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 !