Okay so i have a code so that upon login it issues a cookie, and when login is successful it re-directs to the proper page but does not register as the user being loged in.
Login code:
<?php
$login_error = "";
if (isset($_POST['login_username']) && isset($_POST['login_password'])) {
$login_username = strip_tags(addslashes(trim($_POST['login_username'])));
$login_password = strip_tags(addslashes(trim($_POST['login_password'])));
if (!empty($login_username) && !empty($login_password)) {
$checkLogin = $db->fetch($db->query("SELECT id, twmauth FROM users WHERE username = '".$login_username."'AND password = '".md5($login_password)."' AND status = '1'"));
if ($checkLogin != NULL) {
setcookie("user_id", $checkLogin['id'], time()+604801, "/", DOMAIN);
setcookie("twmauth", $checkLogin['twmauth'], time()+604801, "/", DOMAIN);
gotoURL(HTTP_SERVER_BASE."websites");
}
else {
$login_error = "Invalid login details. Try again.";
}
}
}
?>
Code dependent if user is loged in:
<?
include('classes/classes_includes.php');
include('includes/includes.php');
include('manage_authentication_actions.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!--<link rel="shortcut icon" href="<?=HTTP_SERVER_BASE;?>images/favicon.ico" />-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var site_url = '<?php echo HTTP_SERVER_BASE; ?>';
</script>
<? include('includes/header_includes.php'); ?></head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '100615053364881',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.login', function(response) {
// do something with response
fbLogin();
});
</script>
<script type="text/javascript">
function fbLogin(){
document.location.href = "<?=HTTP_SERVER_BASE;?>facebook_auth";
}
</script>
<style type="text/css">
.box{
margin: 5px;
border: 1px solid #60729b;
padding: 5px;
width: 500px;
height: 200px;
overflow:auto;
background-color: #e6ebf8;
}
</style>
<iframe name="hiddenFrame" id="hiddenFrame" src="" style="display: block;"></iframe>
<div id="<?php if ($isHome) { ?>home_<?php } ?>wrapper">
<div class="<?php if ($isHome) { ?>home_<?php } ?>site_width">
<div id="header" <?php if ($isHome) {?>style="padding-bottom: 0px; padding-top: 0px;"<?php } ?>>
<?php
if ($isHome) {
?>
<div class="home_login">
<form name="loginForm" action="" method="post" onsubmit="login(); return false;">
<table class="login_table" cellpadding="3" cellspacing="0" border="0">
<tr>
<td class="left">Username:</td>
<td class="right"><input class="input" type="text" name="login_username" id="login_username" style="width: 100px;" maxlength="14" value="<?php echo strip_tags(addslashes(trim($_POST['login_username']))); ?>" /></td>
</tr>
<tr>
<td class="left">Password:</td>
<td class="right"><input class="input" type="password" name="login_password" id="login_password" style="width: 100px;" maxlength="50" /></td>
</tr>
<tr>
<td class="forgot"><a href="<?php echo HTTP_SERVER_BASE; ?>forgot_password">Forgot?</a></td>
<td style="text-align: right;"><input type="image" src="<?php echo HTTP_SERVER_BASE; ?>images/login_bt.png" /></td>
</tr>
</table>
</form>
</div>
<div id="login_error">
<?php if (isset($login_error)) echo $login_error; ?>
</div>
<div class="home_logo"></div>
<?php
} else {
?>
<div id="logo"><a href="<?=HTTP_SERVER_BASE;?>"><img src="<?=HTTP_SERVER_BASE;?>images/logo.png" alt="Twimates" border="0" /></a></div>
<?php
if ($loggedIn) {
?>
<div class="user_header">
Signed in as <strong style="color: #00b4ff;"><?php echo $user->username; ?></strong>
<?php
if ($user->is_premium == 1) {
?>
<strong style="color: #000000;">*premium member*</strong>
<?php
}
?>
<a href="<?php echo HTTP_SERVER_BASE; ?>settings">Settings</a> | <a href="<?php echo HTTP_SERVER_BASE; ?>support">Support</a> | <a href="<?php echo HTTP_SERVER_BASE; ?>logout">Logout</a>
<br />
<div class="grains">
Grain count:
<br />
<div class="grain_count" id="grain_count"><?php echo $user->getGrains(); ?></div>
<!--<a href="#">Free grains</a>-->
</div>
</div>
<?php } else { ?>
<div class="home_login" style="margin-left: 790px;">
<form name="loginForm" action="" method="post" onsubmit="login(); return false;">
<table class="login_table" cellpadding="3" cellspacing="0" border="0">
<tr>
<td class="left">Username:</td>
<td class="right"><input class="input" type="text" name="login_username" id="login_username" style="width: 100px;" maxlength="14" value="<?php echo strip_tags(addslashes(trim($_POST['login_username']))); ?>" /></td>
</tr>
<tr>
<td class="left">Password:</td>
<td class="right"><input class="input" type="password" name="login_password" id="login_password" style="width: 100px;" maxlength="50" /></td>
</tr>
<tr>
<td class="forgot"><a href="<?php echo HTTP_SERVER_BASE; ?>forgot_password">Forgot?</a></td>
<td style="text-align: right;"><input type="image" src="<?php echo HTTP_SERVER_BASE; ?>images/login_bt.png" /></td>
</tr>
</table>
</form>
</div>
<div id="login_error" style="margin-left: 790px;">
<?php if (isset($login_error)) echo $login_error; ?>
</div>
<?php } ?>
<?php } ?>
<div style="clear: both;"></div>
<?php
include('tabs.php');
?>
</div>
<div class="extra_seeds">
</div>
</div>
<div id="content">
Please Help