perezf Posted September 11, 2006 Share Posted September 11, 2006 im having problems with my cookieswhen i log in and click on the link it doesnt keep me logged inhere is the code[code]<?phpif((!$_POST['username']) || (!$_POST['password'])) { header("Location: show_login.html"); exit;}// Database Name$db_name = "users";// Database Table Name$table_name = "auth_users";// database server$dbhost = "localhost";// database username$dbusername = "username";//database password$dbpassword = "password";//connection to Database$connection = @mysql_connect($dbhost, $dbusername, $dbpassword) or die(mysql_error()); // Select Database$db = @mysql_select_db($db_name, $connection) or die(mysql_error());// Create Sql Statement$sql = "SELECT * FROM $table_name WHERE username = '$_POST[username]' && password = password('$_POST[password]')"; // Holds the result of mysql_query$result = @mysql_query($sql, $connection) or die(mysql_error()); // checks for results$num = mysql_num_rows($result);if($num !=0) { $cookie_name = "auth"; $cookie_value = "ok"; $cookie_expire = "0"; $cookie_domain = "http://2fr3sh.com/login"; setcookie($cookie_name, $cookie_value, $cookie_expire, "/", $cookie_domain, 0); $display_block = " <p><strong>Secret Menu:</strong></p> <ul> <li><a href=\"secretA.php\">secret page A</a> <li><a href=\"secretB.php\">secret page B</a> </ul>"; } else { header("Location: show_login.html"); exit; }?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Secret Area</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php echo "$display_block"; ?></body></html>[/code]code for secret page[code]<?phpif($COOKIE[auth] == "ok") { $msg = "<p>Welcome to secret page A, authorized user!</p>"; } else { header("Location: show_login.html"); exit; }?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Secret Page A</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head><body><?php echo "$msg"; ?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.