Jump to content

Cookies with login system?


ChrisMartino

Recommended Posts

Hey my login system is pritty basic at the moment, When you leave the page and come back your not logged in anymore, I've looked at some tutorials on cookies and attempted them  but all my attempts have failed, Could somebody show me how to fix this so it keeps you logged in for a month?

 

This is my login.php so you get the idea of the variables i used:

 

<?php include "Main/Database/base.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta name="Description" content="Information architecture, Web Design, Web Standards." />
<meta name="Keywords" content="your, keywords" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Distribution" content="Global" />
<meta name="Author" content="Erwin Aligam - [email protected]" />
<meta name="Robots" content="index,follow" />

<link rel="stylesheet" href="images/MarketPlace.css" type="text/css" />

<LINK REL="SHORTCUT ICON"
       HREF="favicon.ico">

<title>Musicians Village - Login</title></title>

</head>

<body>

<!-- wrap starts here -->
<div id="wrap">

<!--header -->
<div id="header">			

	<div id="header-links">
	<p>
	<?php
		if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
		{
 	?>
    				<p>Logged in as: <a href="profile.php"><b><?=$_SESSION['Username']?></a></b> | Account: <?=$_SESSION['AccountType']?> | <a href="logout.php">Logout</a> </p>

	<?php
		}
		else
		{
	?>
			<p>Welcome <b>Guest</b>, Please <a href="login.php">Login</a> or <a href="register.php">Register</a></p>
	<?php
		}
	?>

    

	</p>		
	</div>		

<!--header ends-->					
</div>

<div id="header-photo"></div>		

<!-- navigation starts-->	
<div  id="nav">
	<ul>
		<li><a href="index.php">Home</a></li>
		<li id="current"><a href="login.php">Login</a></li>
		<li><a href="register.php">Register</a></li>			
		<li><a href="track.php?action=upload">Submit Track</a></li>
		<li><a href="track.php?action=listen">Listen To Tracks</a></li>
		<li><a href="/forums">Forums</a></li>
		<li><a href="contact.php">Contact</a></li>		
	</ul>
<!-- navigation ends-->	
</div>					

<!-- content-wrap starts -->
<div id="content-wrap" class="three-col"  >	

	<div id="sidebar">


		<h1>Sponsors</h1>
		<ul class="sidemenu">				
			<li><a href="index.html">Home</a></li>
			<li><a href="#TemplateInfo">Template Info</a></li>
			<li><a href="#SampleTags">Sample Tags</a></li>
			<li><a href="http://www.styleshout.com/">More Free Templates</a></li>	
			<li><a href="http://www.4templates.com/?aff=ealigam">Premium Templates</a></li>	
		</ul>	


	<!-- sidebar ends -->		
	</div>

	<div id="rightcolumn">

		<h1>Forum Stats</h1>
		<p>Top poster stuff here</p>

		<h1>*Newest track</h1>
		<p>it is here too! </p>				

	</div>


	<div id="main">

		<a name="TemplateInfo"></a>


		<p>
			<?php
				if(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username']))
				{
 			?>
    
    					<h1>Error: You are already logged in as: <b><?=$_SESSION['Username']?></b>!</h1>
    
    				<?php
				}

				elseif(!empty($_POST['username']) && !empty($_POST['password']))
				{
 					$username = mysql_real_escape_string($_POST['username']);
    						$password = md5(mysql_real_escape_string($_POST['password']));
    
 					$checklogin = mysql_query("SELECT * FROM users WHERE Username = '".$username."' AND Password = '".$password."'");
    
    						if(mysql_num_rows($checklogin) == 1)
    						{
    	 						$row = mysql_fetch_array($checklogin);
        						$email = $row['EmailAddress'];
						$AccountType = $row['AccountType'];
						$AccountPic = $row['ProfilePic'];
        						$AccountIP = $row['ip'];

        						$_SESSION['Username'] = $username;
        						$_SESSION['EmailAddress'] = $email;
						$_SESSION['AccountType'] = $AccountType;
						$_SESSION['AccountPic'] = $AccountPic;
						$_SESSION['AccountIP'] = $AccountIP;
        						$_SESSION['LoggedIn'] = 1;

						$ip=$_SERVER['REMOTE_ADDR'];
						$picUPDATE = mysql_real_escape_string($ip);
						$picUPDATEUSR = mysql_real_escape_string($username);
						$changepic = mysql_query("UPDATE  `a7331843_account`.`users` SET  `ip` =  '".$picUPDATE."' WHERE  `users`.`Username` = '".$picUPDATEUSR."' LIMIT 1 ");



			?>

       							<p>You have been logged in, Account type: <?=$_SESSION['AccountType']?>

						<meta http-equiv="REFRESH" content="0;url=index.php"></HEAD>
						<?php
    						}
    						else
    						{
    	 						echo "<h1>Error</h1>";
        						echo "<p>Sorry, Incorrect Username or Password <a href=\"index.php\">click here to try again</a>.</p>";
    						}
				}
				else
				{
			?>
    
   				<h1>Member Login</h1>
    
   				<p>Thanks for visiting! Please either login below, or <a href="register.php">click here to register</a>.</p>
    
			<form method="post" action="login.php" name="loginform" id="loginform">

			<fieldset>
				<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
				<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
				<br />
				<input type="submit" name="login" id="login" value="Login" />
			</fieldset>
			</form>
    
   				<?php
			}
			?>


		</p>  


	</div>

<!-- content-wrap ends-->	
</div>

<!-- footer starts -->			
<div id="footer-wrap"><div id="footer">				

		<p>
		© 2006 <strong>Your Company</strong> | 
		Design by: <a href="http://www.styleshout.com/">styleshout</a> | 
		Valid <a href="http://validator.w3.org/check?uri=referer">XHTML</a> | 
		<a href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a>

   		      

		<a href="index.html">Home</a> | 
   		<a href="index.html">Sitemap</a> | 
   	<a href="index.html">RSS Feed</a>
		</p>		

</div></div>
<!-- footer ends-->	

<!-- wrap ends here -->
</div>

</body>
</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/188701-cookies-with-login-system/
Share on other sites

Archived

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

×
×
  • 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.