Page 1 of 1
How to determine if cookie is set
Posted: Sat Aug 07, 2004 4:07 pm
by ddragas
How to determine if cookie is set
Posted: Sat Aug 07, 2004 4:11 pm
by Joe
Code: Select all
print($HTTP_COOKIE_VARSї'Cookiename']);
Posted: Sat Aug 07, 2004 4:14 pm
by ddragas
Maybe it's silly question but
how to give a neme to a cookie
Posted: Sat Aug 07, 2004 4:17 pm
by feyd
setcookie('name','value',expiry_time,path,domain,is_secure)
Posted: Sat Aug 07, 2004 4:17 pm
by evilmonkey
[php_man]setcookie[/php_man]
Posted: Sat Aug 07, 2004 4:17 pm
by qads
you name it when you set a
cookie
Code: Select all
<?php
setcookie("namehere", $value, time()+expirey in secs);
?>
Posted: Sat Aug 07, 2004 4:18 pm
by tim
go to php.net and type in setcookie and read on it.
clearly you need to know the knowledge before u tamper with cookies cause it poses alot of security risks.
edit
man beaten by three people, usually its just feyd
haha
Posted: Sat Aug 07, 2004 4:28 pm
by ddragas
here is my whole problem.
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;");
}
?>
and code for retrive value from cookie:
Code: Select all
if(isset($_COOKIE["valid"])){
$email = $_COOKIE['email'];
$lozinka = $_COOKIE['lozinka'];
} else{
$email =$e_mail;
$lozinka = md5 ($lozink_a);}
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
Posted: Sat Aug 07, 2004 4:33 pm
by evilmonkey
First off, use
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
?>
And you don't have to say name= and value=.
Good luck!
Posted: Sat Aug 07, 2004 4:41 pm
by ddragas
I'm setting 2 cookies becouse I have two values: e-mail and password. Can I put two values in same cookie?
Posted: Sat Aug 07, 2004 4:47 pm
by evilmonkey
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.
Posted: Sat Aug 07, 2004 5:09 pm
by timvw
evilmonkey wrote:
Code: Select all
<?php
setcookie("name", "value", time()+3600);?>
Instead of time()+3600 i prefer strtotime("+1 day");
Posted: Sat Aug 07, 2004 5:14 pm
by ddragas
Thank you all