PHP - Replace login with user details

  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

Well, i've taken the next step, and im working up the ladder. Let me explain.

I've started creating the register/login functions for my web project, and plesently surprised myself when it worked. Go Dreamweaver! Anyway, what I am struggling to find out is...

- On some websites when you visit and login, when you return to that original login page the login facility has been replaced with your own username, and the login textfields are no longer there. How can I get this to happen. The login facility on my website appears on the homepage, and so when the user returns to that page during browsing, I want them to now they are still logged in because that login feature has been replaced with their details.

How do I do this, and equally, when they log out, how do I make it go back again to allow login. I hope you understand what I mean.

Any instruction on how to do this in Dreamweaver would be wonderful, but any other help is great also.

Thank you for your help :)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Veter
  • Novice
  • Novice
  • User avatar
  • Posts: 20

Post 3+ Months Ago

Use sessions & cookies for this.

Here is the link for you:
http://www.hotscripts.com/Detailed/35886.html
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

okay let me get this straith you want to have a link on your webpage to something like... profile.php. anytime when your users are loged in, and moving around your webpage you want them to be able to click that link and it will take them to there profile.php page... with out having to relogin right?

and if this is so, then use cookies ^^ like Veter said...

if you need help with cookies just ask.
  • harryhood
  • Graduate
  • Graduate
  • harryhood
  • Posts: 141

Post 3+ Months Ago

One thing you need to do is set a variable or cookie that you will check later, each time a user logins in. Something like $IsLoggedin.

Then on each page where the login facility is you check for the existence of the variable/cookie that you have set. If it exists then display the login information, if not display the login facility.

Something like:

PHP Code: [ Select ]
 
<? if(session_is_registered(IsLoggedin)){  ?>
 
   
 
.....
 
DISPLAY USER INFORMATION
 
.....
 
     
 
     
 
   <? } else { ?>
 
.....
 
LOGIN fACILITY
 
.....
 
 </form>
 
 <? } ?>
 
 
  1.  
  2. <? if(session_is_registered(IsLoggedin)){  ?>
  3.  
  4.    
  5.  
  6. .....
  7.  
  8. DISPLAY USER INFORMATION
  9.  
  10. .....
  11.  
  12.      
  13.  
  14.      
  15.  
  16.    <? } else { ?>
  17.  
  18. .....
  19.  
  20. LOGIN fACILITY
  21.  
  22. .....
  23.  
  24.  </form>
  25.  
  26.  <? } ?>
  27.  
  28.  
  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

could you expand on the above and explain how I can use this?
  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

prehaps I can better explain...

HERE IS THE PAGE - http://www.members.lycos.co.uk/afcbboat/
(please do not over use bandwidth)

Login bottom of page - username: guest, password: guest

When you return to the login section at http://www.members.lycos.co.uk/afcbboat/ the login box remain, but I want it to say something like, "You are already logged in. Log out?", and offer a log out option.

Please help. Thanks.
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Well, I'm guessing your using sessions for your logins.
You can do something like this.
PHP Code: [ Select ]
if($_SESSION['user_id'] > 0) {
 
     //Show what you want to be shown while they are logged in.
 
} else {
 
    //Show the form so they can login.
 
    echo "<form method=\"post\" action=\"login.php\">
 
              Username:<input type=\"text\" name=\"username\"><br>
 
              Password:<input type=\"password\" name=\"password\"><br>
 
              <input type=\"submit\" name=\"login\" value=\"Login\">
 
         </form>";
 
}
  1. if($_SESSION['user_id'] > 0) {
  2.  
  3.      //Show what you want to be shown while they are logged in.
  4.  
  5. } else {
  6.  
  7.     //Show the form so they can login.
  8.  
  9.     echo "<form method=\"post\" action=\"login.php\">
  10.  
  11.               Username:<input type=\"text\" name=\"username\"><br>
  12.  
  13.               Password:<input type=\"password\" name=\"password\"><br>
  14.  
  15.               <input type=\"submit\" name=\"login\" value=\"Login\">
  16.  
  17.          </form>";
  18.  
  19. }

I don't know the variables you set in your sessions so I just guessed you might use a userid.
Hope that will help you out.
  • dbzl
  • Born
  • Born
  • User avatar
  • Posts: 3

Post 3+ Months Ago

When someone logs in start a session with their username in it:
PHP Code: [ Select ]
 
<?php
 
session_start();
 
header("Cache-control: private");
 
$_SESSION['username'] = $username;
 
?>
 
 
  1.  
  2. <?php
  3.  
  4. session_start();
  5.  
  6. header("Cache-control: private");
  7.  
  8. $_SESSION['username'] = $username;
  9.  
  10. ?>
  11.  
  12.  


Well, something like that and then at your login page:
PHP Code: [ Select ]
 
<?php
 
if(!$_SESSION['username'])
 
{
 
?>
 
<form method="post" action=<?php echo $_SERVER[PHP_SELF]; ?>>
 
Username:<br>
 
<input name=username type=text size=16 value=<?php echo $HTTP_COOKIE_VARS["username"]; ?>><br>
 
Password:<br>
 
<input name=password type=password size=21><br>
 
<input type=submit name=submit value=Login>
 
</form>
 
<?php
 
}
 
else
 
{
 
?>
 
Logged in as: <?php echo $_SESSION['username']; ?><br>
 
<a href=logout.php>Logout</a>
 
<?php
 
}
 
?>
 
 
  1.  
  2. <?php
  3.  
  4. if(!$_SESSION['username'])
  5.  
  6. {
  7.  
  8. ?>
  9.  
  10. <form method="post" action=<?php echo $_SERVER[PHP_SELF]; ?>>
  11.  
  12. Username:<br>
  13.  
  14. <input name=username type=text size=16 value=<?php echo $HTTP_COOKIE_VARS["username"]; ?>><br>
  15.  
  16. Password:<br>
  17.  
  18. <input name=password type=password size=21><br>
  19.  
  20. <input type=submit name=submit value=Login>
  21.  
  22. </form>
  23.  
  24. <?php
  25.  
  26. }
  27.  
  28. else
  29.  
  30. {
  31.  
  32. ?>
  33.  
  34. Logged in as: <?php echo $_SESSION['username']; ?><br>
  35.  
  36. <a href=logout.php>Logout</a>
  37.  
  38. <?php
  39.  
  40. }
  41.  
  42. ?>
  43.  
  44.  


Hope that's what your looking for. I don't use dreamweaver but i guess u just instert the code
  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

Still can't get it to work right, prehaps if I supply some more information.

Login facility is on index.php

Database for registered users, 3 fields = username (primary), password, email.


i would like to set up a profile page. How do I go about this?
  • harryhood
  • Graduate
  • Graduate
  • harryhood
  • Posts: 141

Post 3+ Months Ago

lomilmand wrote:
Still can't get it to work right, prehaps if I supply some more information.

Login facility is on index.php

Database for registered users, 3 fields = username (primary), password, email.


i would like to set up a profile page. How do I go about this?


What does the code look like that you use to check the validity of a user during the login process?
  • lomilmand
  • Student
  • Student
  • lomilmand
  • Posts: 91
  • Loc: Bournemouth, UK

Post 3+ Months Ago

This is the php on the login page

PHP Code: [ Select ]
 
 
 
<?php require_once('Connections/afcbboat.php'); ?>
 
<?php
 
//initialize the 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_unregister('MM_Username');
 
  session_unregister('MM_UserGroup');
 
   
 
  $logoutGoTo = "log_out_success.htm";
 
  if ($logoutGoTo) {
 
    header("Location: $logoutGoTo");
 
    exit;
 
  }
 
}
 
?><?php
 
// *** Validate request to login to this site.
 
session_start();
 
 
 
$loginFormAction = $_SERVER['PHP_SELF'];
 
if (isset($accesscheck)) {
 
  $GLOBALS['PrevUrl'] = $accesscheck;
 
  session_register('PrevUrl');
 
}
 
 
 
if (isset($_POST['Username'])) {
 
  $loginUsername=$_POST['Username'];
 
  $password=$_POST['Password'];
 
  $MM_fldUserAuthorization = "Level";
 
  $MM_redirectLoginSuccess = "login_success.php";
 
  $MM_redirectLoginFailed = "register.php";
 
  $MM_redirecttoReferrer = false;
 
  mysql_select_db($database_afcbboat, $afcbboat);
 
   
 
  $LoginRS__query=sprintf("SELECT Username, Password, Level FROM Users WHERE Username='%s' AND Password='%s'",
 
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
 
   
 
  $LoginRS = mysql_query($LoginRS__query, $afcbboat) or die(mysql_error());
 
  $loginFoundUser = mysql_num_rows($LoginRS);
 
  if ($loginFoundUser) {
 
   
 
    $loginStrGroup  = mysql_result($LoginRS,0,'Level');
 
   
 
    //declare two session variables and assign them
 
    $GLOBALS['MM_Username'] = $loginUsername;
 
    $GLOBALS['MM_UserGroup'] = $loginStrGroup;       
 
 
 
    //register the session variables
 
    session_register("MM_Username");
 
    session_register("MM_UserGroup");
 
 
 
    if (isset($_SESSION['PrevUrl']) && false) {
 
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];   
 
    }
 
    header("Location: " . $MM_redirectLoginSuccess );
 
  }
 
  else {
 
    header("Location: ". $MM_redirectLoginFailed );
 
  }
 
}
 
?>
  1.  
  2.  
  3.  
  4. <?php require_once('Connections/afcbboat.php'); ?>
  5.  
  6. <?php
  7.  
  8. //initialize the session
  9.  
  10. session_start();
  11.  
  12.  
  13.  
  14. // ** Logout the current user. **
  15.  
  16. $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
  17.  
  18. if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  19.  
  20.   $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
  21.  
  22. }
  23.  
  24.  
  25.  
  26. if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  27.  
  28.   //to fully log out a visitor we need to clear the session varialbles
  29.  
  30.   session_unregister('MM_Username');
  31.  
  32.   session_unregister('MM_UserGroup');
  33.  
  34.    
  35.  
  36.   $logoutGoTo = "log_out_success.htm";
  37.  
  38.   if ($logoutGoTo) {
  39.  
  40.     header("Location: $logoutGoTo");
  41.  
  42.     exit;
  43.  
  44.   }
  45.  
  46. }
  47.  
  48. ?><?php
  49.  
  50. // *** Validate request to login to this site.
  51.  
  52. session_start();
  53.  
  54.  
  55.  
  56. $loginFormAction = $_SERVER['PHP_SELF'];
  57.  
  58. if (isset($accesscheck)) {
  59.  
  60.   $GLOBALS['PrevUrl'] = $accesscheck;
  61.  
  62.   session_register('PrevUrl');
  63.  
  64. }
  65.  
  66.  
  67.  
  68. if (isset($_POST['Username'])) {
  69.  
  70.   $loginUsername=$_POST['Username'];
  71.  
  72.   $password=$_POST['Password'];
  73.  
  74.   $MM_fldUserAuthorization = "Level";
  75.  
  76.   $MM_redirectLoginSuccess = "login_success.php";
  77.  
  78.   $MM_redirectLoginFailed = "register.php";
  79.  
  80.   $MM_redirecttoReferrer = false;
  81.  
  82.   mysql_select_db($database_afcbboat, $afcbboat);
  83.  
  84.    
  85.  
  86.   $LoginRS__query=sprintf("SELECT Username, Password, Level FROM Users WHERE Username='%s' AND Password='%s'",
  87.  
  88.   get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  89.  
  90.    
  91.  
  92.   $LoginRS = mysql_query($LoginRS__query, $afcbboat) or die(mysql_error());
  93.  
  94.   $loginFoundUser = mysql_num_rows($LoginRS);
  95.  
  96.   if ($loginFoundUser) {
  97.  
  98.    
  99.  
  100.     $loginStrGroup  = mysql_result($LoginRS,0,'Level');
  101.  
  102.    
  103.  
  104.     //declare two session variables and assign them
  105.  
  106.     $GLOBALS['MM_Username'] = $loginUsername;
  107.  
  108.     $GLOBALS['MM_UserGroup'] = $loginStrGroup;       
  109.  
  110.  
  111.  
  112.     //register the session variables
  113.  
  114.     session_register("MM_Username");
  115.  
  116.     session_register("MM_UserGroup");
  117.  
  118.  
  119.  
  120.     if (isset($_SESSION['PrevUrl']) && false) {
  121.  
  122.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];   
  123.  
  124.     }
  125.  
  126.     header("Location: " . $MM_redirectLoginSuccess );
  127.  
  128.   }
  129.  
  130.   else {
  131.  
  132.     header("Location: ". $MM_redirectLoginFailed );
  133.  
  134.   }
  135.  
  136. }
  137.  
  138. ?>
  • harryhood
  • Graduate
  • Graduate
  • harryhood
  • Posts: 141

Post 3+ Months Ago

You can use the session_is_registered() function to check for the MM_Username session variable that is set at login. In my example it would look something like:

PHP Code: [ Select ]
<? if(session_is_registered(MM_Username)){  ?>
 
     
 
.....
 
DISPLAY USER INFORMATION
 
echo $MM_Username;
 
.....
 
         
 
         
 
    <? } else { ?>
 
.....
 
LOGIN fACILITY
 
.....
 
</form>
 
<? } ?>
 
 
  1. <? if(session_is_registered(MM_Username)){  ?>
  2.  
  3.      
  4.  
  5. .....
  6.  
  7. DISPLAY USER INFORMATION
  8.  
  9. echo $MM_Username;
  10.  
  11. .....
  12.  
  13.          
  14.  
  15.          
  16.  
  17.     <? } else { ?>
  18.  
  19. .....
  20.  
  21. LOGIN fACILITY
  22.  
  23. .....
  24.  
  25. </form>
  26.  
  27. <? } ?>
  28.  
  29.  


See
http://us4.php.net/manual/en/function.session-is-registered.php for more details

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 89 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.