Location: PHPKode > projects > WH Community > wh_community/signin.php
<?php require('layout/header.php'); ?>

    <script type="text/javascript">
    	function showSuccessMessage() {
    	showNotification({
    	type : "success",
    	message: "<?php echo $lang['success_signin']; ?>"
    	});    
        }                                
    
    function showErrorMessage() {
    	showNotification({
    	type : "error",
    	message: "<?php echo $lang['couldnot_signin']; ?>"
    	});    
        }                                
    </script>

<div id="content_wrapper">
    <div class="content"><?php

		echo '<h1>' . $lang['signin'] . '</h1><br>';
		
		if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == TRUE) {
		
		echo '<p>' . $lang['already_signedin'] . ' <a href="signout.php">' . $lang['signout_s'] . '</a>.</p>';
		
			}else{
			
			if($_SERVER['REQUEST_METHOD'] != 'POST') {
			
			echo '<form method="post" action="">
			      <p><input type="text" class="fields" name="user_name" size="30"> <strong>User Name</strong></p>
			      <p><input type="password" class="fields" name="user_pass" size="30"> <strong>' . $lang['password'] . '</strong></p>
			      <p><input type="checkbox" name="remember" value="1"> <em>' . $lang['remember_me'] . '?</em></p>
			      <p><input type="submit" class="button" value="' . $lang['signin_s'] . '" alt="' . $lang['signin_s'] . '"></p><br>
			      </form>
			      <p><a href="forgotten.php" class="sign_in">' . $lang['forgot_my_pass'] . '</a> &nbsp;|&nbsp; <a href="signup.php" class="sign_in">' . $lang['register_now'] . '</a></p><br>';
		
		}else{
		
		$errors = array(); 
		
		if(!isset($_POST['user_name'])) {
		$errors[] = '<p>' . $lang['choose_user_name'] . ' [ <a href="javascript:history.back();">' . $lang['back'] . '</a> ]</p>';
		}
		
		if(!isset($_POST['user_pass'])) {
		$errors[] = '<p>' . $lang['choose_password'] . ' [ <a href="javascript:history.back();">' . $lang['back'] . '</a> ]</p>';
		}
		
		if(!empty($errors)) {
		
		echo '<p>' . $lang['not_filled_all'] . ' [ <a href="javascript:history.back();">' . $lang['back'] . '</a> ]</p>';
		echo '<ul>';
		
		foreach($errors as $key => $value) {
		echo '<li>' . $value . '</li>'; 
		}
		echo '</ul>';
		
			}else{
			
			$sql = "SELECT 
						user_id,
						user_name,
						user_level
					FROM
						users
					WHERE
						user_name = '" . mysql_real_escape_string($_POST['user_name']) . "'
					AND
						user_pass = '" . sha1($_POST['user_pass']) . "'
					AND
						`user_active` = '1'";
			
			$result = mysql_query($sql) OR die(mysql_error());
			
			if(!$result) {
			
			echo '<p class="false">' . $lang['login_failed'] . '</p>
			      <p>[ <a href="signin.php">' . $lang['signin_to'] . '</a> ]</p><br>';
		
		}else{
		
		if(intval(mysql_num_rows($result)) == 0) {
		
		echo '<p class="false">' . $lang['combination_invalid'] . '<br><small>' . $lang['acc_already_activated'] . '?</small></p>
		      <p>[ <a href="signin.php">' . $lang['signin_to'] . '</a> ]</p><br>';
		echo "<script type=\"text/javascript\">showErrorMessage();</script>";
		
    		}else{
    		
    		$_SESSION['signed_in'] = TRUE;
    		
    		while($row = mysql_fetch_assoc($result)) {
    		
        		$_SESSION['user_id'] 	= (int)$row['user_id'];
        		$_SESSION['user_name'] 	= htmlentities($row['user_name'], ENT_QUOTES);
        		$_SESSION['user_level'] = (int)$row['user_level'];
        		}
    		
    		$lsi = "UPDATE
    					users
    				SET
    					user_status = NOW(),
    					user_visits = user_visits + 1
    				WHERE
    					user_id = " . (int)$_SESSION['user_id'];
    		
    		$lsiresult = mysql_query($lsi) OR die(mysql_error());
        
        if(isset($_POST['remember']) AND $_POST['remember'] == 1) {
        
            setcookie('user_name', $_POST['user_name'], time() + $cookie_time);
            setcookie('user_pass', sha1($_POST['user_pass']), time() + $cookie_time);
        
                }else{ }
        
		if(!$lsiresult) {
		
		echo '<p class="false">' . $lang['error_occurred'] . '!</p>
		      <p>[ <a href="signin.php">' . $lang['signin_to'] . '</a> ]</p>';
		
		close_connection();
		
			}else{
			
			$autoforward = 3;
			echo '<p>' . $lang['welcome'] . ', <strong><u>' . htmlentities($_SESSION['user_name'], ENT_QUOTES) . '</u></strong></p>
			      <p><meta http-equiv="refresh" content="' . $autoforward . '; URL=' . $index . '">
			      <small>(' . $lang['redirected_in'] . ' ' . $autoforward . ' ' . $lang['seconds'] . '...)</small></p>';
			echo "<script type=\"text/javascript\">showSuccessMessage();</script>";
			}
		
		}}}}}
		
		echo '<div class="spacer_div">&nbsp;</div>';

		?>
    </div>
</div>

<div id="infobox_wrapper">
    <div class="infobox">
        <?php include('layout/infobox.php'); ?>
    </div>
</div>

<?php require('layout/footer.php'); ?>
Return current item: WH Community