Jump to content

help with cookies


perezf

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.