Member login/registration Help

Sportsman9987

New Member
Okay so I have created a registration form and a login form. Im using dreamweaver cs3 and i got everything set up using server behaviors. So when someone registers it gets sent to a user database and then when you login it looks through that database to make sure the username matches the password and everything is right. What my question is what to do from there. I would like to make something so that when someone is logged in they know there logged in. Something as simple as even after logging in it redirects to the home page(which it already does) and then it will say like Welcome, John. or whatever your entered name was on your registration.

If anyone has any ideas on how to do something like that. OR any ideas of what else i can do with my newly established member login/registration feature i would greatly appreciate some advice. Also for the record im sort of new to web design/php/sql/programming stuff but im a fast learner :)
 

conor

New Member
Are you using PHP?

If so then you could sessions. A session lets you share information between multiple pages. In your application add this line after you have verified the users login:

Code:
session_start();
$_SESSION['logged_in']=1;

Then at the top of every page you want to use this session variable add:

Code:
session_start();

Now if you want to execute a piece of code when someone is logged in then use this if statement:

Code:
if(@$_SESSION['logged_in']==1){
   echo 'You are logged in!';
}

If you want to do a personalised message to the user then you will have to get their name from the database and then echo it. Or else you could store their name in another session variable when they log in so you have access to it all the time.
 

Sportsman9987

New Member
Yes i am using php, thanks. Im not 100% sure if i understand how to do everything you just said but ill try my best and see if it works. And yes i have their names saved in the database too so just something that uses the firstname from the database would work.
 

Sportsman9987

New Member
AWESOME! i got it to work, thank you very very much. Now do you know what the script would be if instead of saying you are logged in! it would say Welcome, then the usernames first name. the usernames first name is saved in a table called users and its under the tag "firstname". Sorry i dont know how to use php very well....still learning. Its probably really simple bu ti just dont know.
 

conor

New Member
Ok. To log out you need to destroy the session and therefore $_SESSION['logged_in'] will no longer equal 1 because it will simply not exists!

Code:
session_destroy();

And as for the welcome message I can give you the outline of the script but it is impossible for me to know exactly how to do it as it will depend on your database layout. I assume that you are using MySQL. Add these lines when they are logging in.

Code:
$query=mysql_query('select firstname from users where username="'.$_POST['username']);
$_SESSION['user']['name']=$query;

Then whenever you want to say the users name you can simply write:

Code:
echo 'Hello, '.$_SESSION['user']['name'];

As I said you will have to adapt that to make it work for you. If you are getting any further errors then post them here. Are they fatal or just warnings?
 

Sportsman9987

New Member
Well this was the error:

Warning: Cannot modify header information - headers already sent by (output started at /home/greatla3/public_html/index.php:8) in /home/greatla3/public_html/index.php on line 27

i will try to do what you just said and see if that fixes it.
 

Sportsman9987

New Member
okay by adding session destroy() it gets rid of the welcome message but now when i log in the message is NEVER there. Is there a certain spot im suppose to have the session destroy? At the moment i have it at the begging of the log out code.

// ** Logout the current user. **
session_destroy();
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
 

Sportsman9987

New Member
hmm im having lot of troubles i dont think im doing this right. I will copy my base code with none of your suggestions and maybe you can make some sense of this. thanks for the help btw.

This is my Index and below it is my member login page.
PHP:
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **

$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "/members.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>GREAT LAKES AQUAPONICS: Learn, Grow, Harvest...</title>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<style type="text/css">
<!--
.style1 {font-size: 36px}
-->
</style></head>

<body onload="MM_preloadImages('/Images/Buttons/Home2.gif','/Images/Buttons/About-Us2.gif','/Images/Buttons/Consulting2.gif','/Images/Buttons/Contacts2.gif','/Images/Buttons/Growblog2.gif','/Images/Buttons/Members2.gif','/Images/Buttons/Store2.gif','/Images/Buttons/FAQ2.gif')">
<table width="1156" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="200" rowspan="2" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td colspan="5" rowspan="2" valign="top"><img src="/Images/Banner2.gif" width="749" height="138" /></td>
    <td width="63" height="24" valign="top"><form id="logout" name="logout" method="post" action="">
      <a href="<?php echo $logoutAction ?>">Log out</a>
                </form></td>
    <td width="43">&nbsp;</td>
    <td width="100">&nbsp;</td>
  </tr>
  <tr>
    <td height="114">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  <tr>
    <td rowspan="4" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="200" height="51" valign="top"><a href="/index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Home Button','','/Images/Buttons/Home2.gif',1)"><img src="/Images/Buttons/Home.gif" name="Home Button" width="200" height="50" border="0" id="Home Button" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('About Us','','/Images/Buttons/About-Us2.gif',1)"><img src="/Images/Buttons/About-Us.gif" name="About Us" width="200" height="50" border="0" id="About Us" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="consulting.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Consulting','','/Images/Buttons/Consulting2.gif',1)"><img src="/Images/Buttons/Consulting.gif" name="Consulting" width="200" height="50" border="0" id="Consulting" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="contactform.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','/Images/Buttons/Contacts2.gif',1)"><img src="/Images/Buttons/Contacts.gif" name="Image4" width="200" height="50" border="0" id="Image4" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Grow Blog','','/Images/Buttons/Growblog2.gif',1)"><img src="/Images/Buttons/Growblog.gif" name="Grow Blog" width="200" height="50" border="0" id="Grow Blog" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="members.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Members','','/Images/Buttons/Members2.gif',1)"><img src="/Images/Buttons/Members.gif" name="Members" width="200" height="50" border="0" id="Members" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Store','','/Images/Buttons/Store2.gif',1)"><img src="/Images/Buttons/Store.gif" name="Store" width="200" height="50" border="0" id="Store" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('FAQ','','/Images/Buttons/FAQ2.gif',1)"><img src="/Images/Buttons/FAQ.gif" name="FAQ" width="200" height="50" border="0" id="FAQ" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        </tr>
      <tr>
        <td height="51" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        </tr>
      <tr>
        <td height="51" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        </tr>
      <tr>
        <td height="3"></td>
        </tr>
      
      
      
      
      
      
      
      
    </table></td>
    <td width="198" height="51">&nbsp;</td>
    <td width="119">&nbsp;</td>
    <td width="195">&nbsp;</td>
    <td width="151">&nbsp;</td>
    <td width="87">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td rowspan="3" valign="top"><!--#exec cgi="cgi-bin/entropybanner.cgi"-->
&nbsp;</td>
  </tr>
  <tr>
    <td height="51">&nbsp;</td>
    <td colspan="3" valign="top"><span class="style1">Site Under Contruction</span></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="71">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="626">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  
  <tr>
    <td height="837">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="35">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td valign="top"><img src="/cgi-sys/Count.cgi?df=greatla3.dat|display=Counter|ft=6|md=5|frgb=100;139;216|dd=A"> &nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  
  
  
  
  <tr>
    <td height="23">&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="3" valign="top">&copy; Spencer Dixon 2009, Great Lakes Aquaponics, llc</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
 

Sportsman9987

New Member
Member login page:


PHP:
<?php include('Connections/Login.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}


// ** Logout the current user. **

$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "/index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}


$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "/index.php";
  $MM_redirectLoginFailed = "/fail.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_Login, $Login);
  
  $LoginRS__query=sprintf("SELECT username, password FROM Users WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $Login) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
	
        //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Member Login</title>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script><style type="text/css">
<!--
.style1 {font-size: 18px}
-->
</style></head>

<body onload="MM_preloadImages('/Images/Buttons/Home2.gif','/Images/Buttons/About-Us2.gif','/Images/Buttons/Consulting2.gif','/Images/Buttons/Contacts2.gif','/Images/Buttons/Growblog2.gif','/Images/Buttons/Members2.gif','/Images/Buttons/Store2.gif','/Images/Buttons/FAQ2.gif')">
<table width="1156" border="0" cellpadding="0" cellspacing="0">
  <!--DWLayoutTable-->
  <tr>
    <td width="200" rowspan="3" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td colspan="8" rowspan="3" valign="top"><img src="/Images/Banner2.gif" width="749" height="138" /></td>
    <td width="56" height="1"></td>
    <td width="149"></td>
  </tr>
  <tr>
    <td height="24" valign="top"><form id="form2" name="form2" method="post" action="">
      <a href="<?php echo $logoutAction ?>">Log out</a>
                        </form></td>
    <td></td>
  </tr>
  <tr>
    <td height="113">&nbsp;</td>
    <td></td>
  </tr>
  
  
  <tr>
    <td rowspan="5" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      <tr>
        <td width="200" height="51" valign="top"><a href="/index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Home Button','','/Images/Buttons/Home2.gif',1)"><img src="/Images/Buttons/Home.gif" name="Home Button" width="200" height="50" border="0" id="Home Button" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('About Us','','/Images/Buttons/About-Us2.gif',1)"><img src="/Images/Buttons/About-Us.gif" name="About Us" width="200" height="50" border="0" id="About Us" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="consulting.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Consulting','','/Images/Buttons/Consulting2.gif',1)"><img src="/Images/Buttons/Consulting.gif" name="Consulting" width="200" height="50" border="0" id="Consulting" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="contactform.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image4','','/Images/Buttons/Contacts2.gif',1)"><img src="/Images/Buttons/Contacts.gif" name="Image4" width="200" height="50" border="0" id="Image4" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Grow Blog','','/Images/Buttons/Growblog2.gif',1)"><img src="/Images/Buttons/Growblog.gif" name="Grow Blog" width="200" height="50" border="0" id="Grow Blog" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Members','','/Images/Buttons/Members2.gif',1)"><img src="/Images/Buttons/Members.gif" name="Members" width="200" height="50" border="0" id="Members" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Store','','/Images/Buttons/Store2.gif',1)"><img src="/Images/Buttons/Store.gif" name="Store" width="200" height="50" border="0" id="Store" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('FAQ','','/Images/Buttons/FAQ2.gif',1)"><img src="/Images/Buttons/FAQ.gif" name="FAQ" width="200" height="50" border="0" id="FAQ" /></a></td>
        </tr>
      <tr>
        <td height="51" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        </tr>
      <tr>
        <td height="51" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        </tr>
      <tr>
        <td height="51" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        </tr>
      <tr>
        <td height="3"></td>
        </tr>
 

lovely09

New Member
A thing i'm still learning to do.It's an introduction page that will make the customer feel that there's someone who welcome them at the site.
 
To access some sections of united.com you must login with your Mileage Plus number and united.com password or email address and password.

*
Don't have a Mileage Plus number? Join Mileage Plus.
*
Have a Mileage Plus number but need a password? Register a password and profile.
*
Already a member of Mileage Plus but don't know your Mileage Plus number? Look up your Mileage Plus number or contact Mileage Plus support.
*
Forgot your password? Please see password support.
 
Top