Jump to content

Archived

This topic is now archived and is closed to further replies.

perezf

help with cookies

Recommended Posts

im having problems with my cookies
when i log in and click on the link it doesnt keep me logged in

here is the code
[code]
<?php
if((!$_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]<?php
if($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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.