Jump to content

Staying logged in


enlighten

Recommended Posts

Hi guys,

 

Im building a website for a company http://www.eminence-logistics.co.uk and the client wants a log in system which im having problems with. The registration system is all working fine.

 

If you go to the website you can see where the login form is.

 

Now when the user isn't logged in i need the form to show, but when the user IS logged in i would like a message replacing the form saying welcome, along with a log out button.

 

How do i do this?

 

Thankyou very much

 

Enlighten

Link to comment
Share on other sites

I been trying to use SESSIONS, how would you do it with these, because everything i seem to try it doesn't work

What have you tried?  Can you post your code?

Tips: Very top of the page have

<?php
session_start();

After verifying user with from processing/DB query set desired values to session. Here's a basic sample with $error variable that can be echoed lower on the page.  Be sure to use same encryption as you have in registration.  MD5 shown here.

<?php
session_start();
$error="";
$username=mysqli_real_escape_string($link, $_POST['username']);
$mdpass=MD5($_POST['password']);
$query = "SELECT user_id,username FROM users WHERE password='$mdpass' AND username='$username'";   
$result = mysql_query($query);
$query_data = mysql_fetch_row($result);
   
  IF (!$query_data[0]) {
$error.="<span class=\"error\">Username and Password Don't match</span><br />";	
} ELSE {
$_SESSION['userid']=$query_data[0];
$_SESSION['username']=$query_data[1];
}
?>

Any information sent to browser needs to come after this.

Link to comment
Share on other sites

I been trying to use SESSIONS, how would you do it with these, because everything i seem to try it doesn't work :(

 

Thanks for the response

 

Make sure you have session_start(); at the top of each page.

 

The general idea is to set a session flag when a user logs in. Something like,

$_SESSION['logged_in'] = true;

 

Once you do that you can load things based on whether a user is logged in or not like this

if ($_SESSION['logged_in'] === true) {
    // user is logged in
} else {
    // user is not logged in
}

Link to comment
Share on other sites

At the moment i have this as my home page. and you can see where hte login form is, basically if the session is equal to 1 i want this bit to say welcome instead of the form if equal to null i want it to stay on same page but for the login form to show. Any thoughts?

 

<?PHP
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: login.php");
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<!-- Meta -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="language" content="en" />
<meta name="robots" content="index,follow" />
<meta name="author" content="Thomas Burman" />
<meta name="description" content="Eminence Logistics is dedicated to delivering innovative, value added logistics solutions with unparalleled levels of service and commitment." />
<meta name="keywords" content="fulfilment,fulfillment,services,order fulfillment,warehousing, pick, pack, retail,shipping,air,freight,sea,fmcg,kent,south,east,UK,distribution" />
<meta name="robots" content="noodp,noydir" />

<!-- CSS -->
	<!--[if IE]>
		<link rel="stylesheet" type="text/css" href="ie-style.css" />
	<![endif]-->
<link rel="stylesheet" type="text/css" href="style.css" />
<link href="css/screen.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/top-nav.css" rel="stylesheet" type="text/css" media="screen" />

<!-- Scripts -->
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script> 
<script type="text/javascript" src="js/easySlider1.7.js"></script>
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.vticker-min.js"></script>
<script type="text/javascript" src="js/top-nav.script.js"></script>
<script type="text/javascript">
		$(document).ready(function(){	
			$("#slider").easySlider({
				auto: true, 
				continuous: true,
				controlsShow: false,
				pause: 6250
			});

			$('#news-container').vTicker({ 
				speed: 1000,
				pause: 6250,
				animation: 'fade',
				mousePause: false,
				showItems: 1
			});
		});	
</script>
  
<title>Eminence Logisitics</title>
</head>

<body>

<!-- Top Banner -->
<div id="top-banner">
	<div id="logo">
		<a href="index.html"><img src="images/CB_EM_LOGO.png" width="350" height="140" alt="Eminence Logistics"/></a>
	</div>
	<div id="top-contact">
		<div id="top-number">
			<p id="call">Call now for free consultation:</p> <p id="no">Tel +44 (0)1634 244074</p>
		</div>
	</div>
	<div id="log-in">
			<h2>Log In Here</h2>
			<form action="check_user.php" method="post" name="" id="">
			  <table width="50%" border="0" align="center" cellpadding="4" cellspacing="0">
				<tr> 
				  <td>Username</td>
				  <td><input name="username" type="text" id="username"></td>
				</tr>
				<tr> 
				  <td>Password</td>
				  <td><input name="password" type="password" id="password"></td>
				</tr>
				<tr> 
				  <td> </td>
				  <td><input type="submit" value="Sign In" class="text_button"></td>
				  <td></td>
				</tr>
			  </table>
			</form> 
			<!-- <p> Member area coming soon! </p> -->
		</div>
</div>

<!-- Main Body -->
<div id="wrapper">
<div id="main-wrapper">
	<div class="menu">
		<ul id="jsddm">
		<li id="home_link"><a href="index.html">Home</a></li>
		<li><a href="about.html">About Us</a></li>
		<li><a href="shipping.html">Shipping</a>
			<ul>
				<li><a href="air.html">Air Cargo</a></li>
				<li><a href="sea.html">Sea Cargo</a></li>
			</ul>
		</li>
		<li><a href="warehousing.html">Warehousing</a>
			<ul>
				<li><a href="trad.html">Traditional</a></li>
				<li><a href="retail.html">Retail/</br>Pick & Pack</a></li>
				<li><a href="fmcg.html">FMCG</a></li>
				<li><a href="ecom.html">Ecommerce</a></li>
			</ul>
		</li>
		<li><a href="distribution.html">Distribution</a>
			<ul>
				<li><a href="deliveries.html">Deliveries</a></li>
				<li><a href="pallets.html">UK Pallets</a></li>
			</ul>
		</li>
		<li><a href="reverse_logs.html">Reverse Logs</a></li>
		<li><a href="packaging.html">Packaging</a></li>
		</ul>
		<br style="clear:left"/>
	</div>
	<div id="top-left-col">
		<div id="social">
			<div id="icon">
				<p class="icon"><a href="#"><img src="images/Twitter_64.png" width="48" height="48" alt="Eminence Logistics on Twitter"/></a></p>
				<p class="icon"><a href="#"><img src="images/Facebook_64.png" width="48" height="48" alt="Eminence Logistics on Facebook"/></a></p>
				<p class="icon"><a href="#"><img src="images/Google_64.png" width="48" height="48" alt="Eminence Logistics on Google +"/></a></p>
			</div>
		</div>
		<div id="quick-link-1" class="sidebar-links">
		<h2 class="ql-title">Track & Trace</h2>
			<!-- <form action="checktrack.php" method="post" name="" id="">
			  <table id="track">
				<tr> 
				  <td>Enter your reference no.</td>
				</tr>
				<tr>
					<td><input name="reference" size="15" type="text" id="reference"></td>
				</tr>
				<tr> 
				  <td><INPUT TYPE="image" SRC="images/track_but.png" HEIGHT="25" WIDTH="100"></td>
				</tr>
			  </table>
			</form> -->
			<p> Track and trace feature coming soon! </p>
		</div>
		</div>
		<div id="slider-outside">
			<div id="slider">
				<ul>				
			<li><img src="slider_images/slide1.jpg" alt="Eminence Logistics | Proffesionalism | Cost Effectiveness | Speed" /></li>
			<li><img src="slider_images/slide2.jpg" alt="Eminence Logistics | Space | Warehousing" /></li>
			<li><img src="slider_images/slide3.jpg" alt="Eminence Logistics | Warehousing" /></li>
			<li><img src="slider_images/slide4.jpg" alt="Eminence Logistics | Delivery | Sea | Air " /></li>	
			<li><img src="slider_images/slide5.jpg" alt="Eminence Logistics | Packaging " /></li>				
		</ul>
			</div>
		</div>
	<div id="left-column">
		<div id="quick-link-2"class="sidebar-links">
			<h2 class="ql-title">Contact Us</h2>
				<form method="POST" name="contactform" action="contact-form-handler.php"> 
				<p>
				<label for='name'>Your Name:</label> <br>
				<input type="text" size="18" name="name">
				</p>
				<p>
				<label for='email'>Email Address:</label> <br>
				<input type="text" size="18" name="email"> <br>
				</p>
				<p>
				<label for='message' >Message:</label> <br>
				<textarea name="message" rows="8" cols="14"></textarea>
				</p>
				<INPUT TYPE="submit" class="button" HEIGHT="35" WIDTH="125"><br>
				</form>
				<script language="JavaScript">
					var frmvalidator  = new Validator("contactform");
					frmvalidator.addValidation("name","req","Please provide your name");
					frmvalidator.addValidation("email","req","Please provide your email");
					frmvalidator.addValidation("email","email",
					  "Please enter a valid email address");
				</script>
		</div>
		<div id="quick-link-3"class="sidebar-links">
			<a href="team.html"><img src="images/meet_team.png" alt=" Eminence Logistics Team"/></a>
		</div>
	</div>
	<div id="right-column">
	<h1 id="main-title">Welcome to Eminence Logistics</h1>
	<p id="text-block-1">
		Eminence Logistics is dedicated to delivering innovative, value added logistics solutions with unparalleled levels of service and commitment.
		We have earned a reputation for our innovation and ability to reduce costs whilst improving service.

	</p>
	<p id="text-block-2">
		Our core services are complemented by a strong understanding of the industry. We are  best placed to deliver 
		supply chain and logistics solutions and benefits. We are a UK company in central Kent and we have a strong 
		network for deliveries, a manufacturing plant & warehouse in Newmarket and forwarding offices in China.
		Operating in a modern, fast-moving logistics arena, we have amassed an enviable skills base and experience in various fields.

	</p>
	<p id="text-block-3">
		Our expertise extends to all areas of the Supply Chain. From shipping to delivery on time and in full, 
		with a large network of third parties who will support and collaborate with us to help your business.
		These areas are Customer services, customs & duty, consulting and negotiating.
	</p>
	</div>
</div>

<!-- Footer -->
<div id="footer">
	<div id="bottom-links">
		<div id="bottom-link-1" class="bottom-links">
		<h2 class="ql-title">Latest News</h2>
			<div id="news-container">
			<ul> 
				<li>
					<div class="news-item">
					<h2>News Item 1</h2>
						jugbit.com jquery vticker more info more info more info more info more info
					</div>
				</li>
				<li>
					<div class="news-item">
					<h2>News Item 2</h2>
						Lorem ipsum dolor sit amet, porta at, imperdiet id neque. more info
					</div>
				</li>
				<li>
					<div class="news-item">
					<h2>News Item 3</h2>
						Lorem ipsum dolor sit amet, consectetur adipiscing elit. more info
					</div>
				</li>
				<li>
					<div class="news-item">
					<h2>News Item 4</h2>
						Lorem ipsum dolor sit amet more info more info more info more info
					</div>
				</li>
			</ul>
			</div>
		</div>
		<div id="bottom-link-2" class="bottom-links">
			<h2 class="ql-title">Request a call back...</h2>
			<a href="call-back.html"><h3>Click here to</br>request a call back</br>for your convenience</h3>
			<img id="call-img" style="float: right;" alt="Eminence Logistics Call Back" src="images/Google voice.png"/></a>
		</div>
		<div id="bottom-link-3" class="bottom-links">
		<div id="inner-3">
			<h2 class="ql-title">Associations</br> &nbsp &nbsp &nbsp we are part of...</h2>
			<img id="pall-ex" class="assoc" src="images/uk-pallets-logo.png">
			<img id="rha" class="assoc" src="images/RHA-logo.png">
			<img id="ukwa" class="assoc" src="images/ukwa_logo.png">
		</div>
		</div>

	<div id="bottom-nav">
		<p id="bot-links">|&nbsp <a href="index.html">Home</a> &nbsp | &nbsp <a href="recruitment.html">Recruitment</a> &nbsp | &nbsp <a href="privacy.html">Privacy Policy</a> &nbsp | &nbsp <a href="sitemap.xml">Site map</a> &nbsp | &nbsp <a href="contact.html">Contact</a> &nbsp |</p>
		<p id="copy">All Rights Reserved &copy Eminence Logistics 2011</p>
		<p id="design"><a href="http://www.enlightenwebdesign.co.uk">Designed by Enlighten Web Design</a></p>
	</div>
</div>
</div>

</body>

</html>

 

 

Thanks again

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.