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!
Just barely learning about how to use cookies. I have "cookie_test.php" setting the cookies and trying to pass it on to a link within "cookie_test.php" named "cookie1.php" when trying to echo the results on "cookie1.php" i receive nothing.
Notice: Undefined variable: cookie_name in c:\Inetpub\wwwroot\cookie1.php on line 2
Notice: Undefined variable: cookie_value in c:\Inetpub\wwwroot\cookie1.php on line 2
,
I'm not exactly sure why the cookies are not passing thru to the link? Is there something I need to edit within php.ini? Or something wrong with my PHP5 and IIS setup? I'm sure it's just me. thanks for help!
the cookie, if properly created, will be stored in $_COOKIE, it will not be created as a variable by itself unless you have register_globals on, which you should not. They will not have the variable names you used (unless you actually passed the same thing as a string in the variable)
since its on the same domain it should be passed through no problem. do you have cookies enabled on your browser? since you set the expire time to be 0 it will be erased after you close your browser, like a session.
if none of that is working try setting the cookie with just 2 paramaters (name and value) or with three (name, value, and a bigger time, like a 1 week expiration)
check the manual for more details
edit: also try print_r($_COOKIES); and see what you get
Array ( [test] => string )
Notice: Use of undefined constant test - assumed 'test' in c:\Inetpub\wwwroot\cookie1.php on line 4
good cookie
thank you both. I'm just learning to make a simple login page. I'm not sure how secure it will be by just using cookies as a check point. Should I give a sha1 hash number to be checked as well with the cookie?
I have 2 files "sessionTEST.php" and "session1.php" I can see the cookies being set and displayed, thx feyd and shiz correcting my code. Here's what I have so far
Notice: Undefined index: username in c:\Inetpub\wwwroot\session1.php on line 3
Notice: Undefined index: password in c:\Inetpub\wwwroot\session1.php on line 4
bad cookie
Array ( [test] => adam )
I see from the array at the end, the name of the cookie is "test" and the $user variable is also known which is "adam" I'm not exactly sure why would it give me a FALSE on the IF statement? And why does it say undefined index. I thought I already defined it in the other file "sessionTEST.php"
post data will not be available on any further pages after submission unless resubmitted to said pages. Therefore, you must pass the post data from the first script to the second in some fashion.