Jump to content


Photo

help with cookies


  • Please log in to reply
No replies to this topic

#1 perezf

perezf
  • Members
  • PipPipPip
  • Advanced Member
  • 301 posts
  • LocationFort Lauderdale

Posted 11 September 2006 - 03:24 AM

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
<?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 for secret page
<?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>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users