Hi everybody,
I'm making a user authorization site(just for practice) using cookies. The problem is: I write the command "setcookie()", but my browser does not set the cookie. I tested it on three browser with all three have cookies enabled, but it wouldn't work. Whar can I do? Here's the code:
Note:Code:<? function doDB() { global $conn; $conn = mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("userauth", $conn) or die(mysql_error()); } function check($user, $pass) { global $conn, $sq_res, $user, $pass; $sq = "select user_id from users where username = '$user' && enc = '$pass'"; $sq_res = mysql_query($sq, $conn) or die(mysql_error()); if (mysql_num_rows($sq_res) == 1) { setcookie("user", "$user", 0, "/", "localhost", 0); setcookie("pass", "$pass", 0, "/", "localhost", 0); } } function auth($auth) { if ($_COOKIE[user] == $user && $_COOKIE[pass] == $pass) { $auth = "true"; } } function logout() { setcookie("user", "", time()-1000, "/", "localhost", 0); setcookie("pass", "", time()-1000, "/", "localhost", 0); } ?>
Any help would be appreciated!I tried also to set a cookie with the function header()![]()



Reply With Quote


Bookmarks