How to determine if cookie is set
Moderator: General Moderators
How to determine if cookie is set
How to determine if cookie is set
Code: Select all
print($HTTP_COOKIE_VARSї'Cookiename']);- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
you name it when you set a cookie
Code: Select all
<?php
setcookie("namehere", $value, time()+expirey in secs);
?>here is my whole problem.
It's about validation, and user pages.
Here is code for seting cookie:
and code for retrive value from cookie:
Now pages are organised in way that every time user comes on this page with code from above (after finished editing his profile) his data should be retrived, and autification that this user is right one.
In this way when user comes back on this page it ask me to login again, becouse value from cookie was not retrived.
Don't know if I've explain my self enough. If you have any questions feel free to ask
Thank you
It's about validation, and user pages.
Here is code for seting cookie:
Code: Select all
<?php
session_start();
$broj = $_SESSION['broj'] ;
$e_mail = $_POST['email'];
$lozink_a = $_POST['lozinka'];
$mail=$e_mail;
$pass=md5 ($lozink_a);
if(isset($mail) and isset($pass)){
$expires_soon = date("l, d-M-y H:i:s", time() + 31536000);
setcookie( "email=$mail; expires=$expires_soon;");
setcookie( "name=valid, lozinka=$pass; expires=$expires_soon;");
}
?>Code: Select all
if(isset($_COOKIE["valid"])){
$email = $_COOKIE['email'];
$lozinka = $_COOKIE['lozinka'];
} else{
$email =$e_mail;
$lozinka = md5 ($lozink_a);}In this way when user comes back on this page it ask me to login again, becouse value from cookie was not retrived.
Don't know if I've explain my self enough. If you have any questions feel free to ask
Thank you
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
First off, use
And you don't have to say name= and value=.
Good luck!
Code: Select all
tags. Secondly, here is your problem. You are setting 2 cookies. Why? Secondly, setcookie works like this:Code: Select all
<?php
setcookie("name", "value", time()+3600); //notice how I use quotes
?>Good luck!
- evilmonkey
- Forum Regular
- Posts: 823
- Joined: Sun Oct 06, 2002 1:24 pm
- Location: Toronto, Canada
Why would you want to put 2 values? If you have 1 value, you can get the rest of them from your database or file or wherever your values are stored?
Registration based entirely on cookies will NOT work (this seems like what you're doing). Some browsers don't even accept cookies, have you thought about that? I suggest using a database to store user information.
Registration based entirely on cookies will NOT work (this seems like what you're doing). Some browsers don't even accept cookies, have you thought about that? I suggest using a database to store user information.
Instead of time()+3600 i prefer strtotime("+1 day");evilmonkey wrote:Code: Select all
<?php setcookie("name", "value", time()+3600);?>