Jump to content


Photo

sessions


  • Please log in to reply
4 replies to this topic

#1 bcraig

bcraig
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 03 May 2006 - 04:46 AM

Im trying to get the username of the person who has just signed to appear at the top of my index page. I had it working getting the name from the form and printing it on my index page but as soon as i add the login script to the form the username wont come through. Can anyone help me please??

index.php
<?php require_once('Connections/conn_testing.php'); ?>
<?php 
session_start(); 
header("Cache-control: private"); //IE 6 Fix 
session_register("$username");
$username = $_POST['username'];
$_SESSION['username'] = $username
?>
<?php
echo 'Welcome to my website '.$_SESSION['username'];
?>
<?php
mysql_select_db($database_conn_testing, $conn_testing);
$query_rs_users = "SELECT id, username, password FROM users ORDER BY id ASC";
$rs_users = mysql_query($query_rs_users, $conn_testing) or die(mysql_error());
$row_rs_users = mysql_fetch_assoc($rs_users);
$totalRows_rs_users = mysql_num_rows($rs_users);
?>



<br />
<a href="test.php">users</a><br>
<a href="log.html">log</a>
<br>
<br>
<?php if(($_SESSION['MM_Username']) =="") { ?>
<a href="login.php">Login</a>
<?php } ?>

<?php if(($_SESSION['MM_Username']) !="") { ?>
<a href="logout.php">Logout</a>
<a href="add.php">add</a>
<?php } ?>

<!-- Repeat Region for Users -->
<?php do { ?>
<?php include('inc/users_tbl.php'); ?>
<?php } while ($row_rs_users = mysql_fetch_assoc($rs_users)); ?>
<?php
mysql_free_result($rs_users);
?>

login.php
<?php require_once('Connections/conn_testing.php'); ?>
<?php
// *** Validate request to login to this site.
session_start();
header("Cache-control: private"); //IE 6 Fix  
?>
<?php
$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 = "";
  $MM_redirectLoginSuccess = "index.php";
  $MM_redirectLoginFailed = "login.php?badlogin=true";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_conn_testing, $conn_testing);
  
  $LoginRS__query=sprintf("SELECT username, password 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, $conn_testing) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
    //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 );
  }
}
?>
<?php if($_GET['badlogin']) { ?>
Incorrect username or password please try again
<?php } ?>


Login
<form action="<?php echo $loginFormAction; ?>" method="POST" name="login">
Username:<input name="username" type="text">
Password:<input name="password" type="password">
<input name="submit" type="submit" value="Login">
</form>


#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 03 May 2006 - 05:12 AM

try taking out the $ in session_register("[!--coloro:red--][span style=\"color:red\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]username");
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 bcraig

bcraig
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 03 May 2006 - 05:17 AM

[!--quoteo(post=370797:date=May 3 2006, 12:12 AM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 3 2006, 12:12 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
try taking out the $ in session_register("[!--coloro:red--][span style=\"color:red\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]username");
[/quote]

Didn't work :(

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 03 May 2006 - 11:11 AM

Take out any instances of session_register as it is not needed. Doing $_SESSION[['username'] = $username would be sufficient. To create a session variable.

#5 bcraig

bcraig
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 04 May 2006 - 05:16 AM

[!--quoteo(post=370832:date=May 3 2006, 06:11 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ May 3 2006, 06:11 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Take out any instances of session_register as it is not needed. Doing $_SESSION[['username'] = $username would be sufficient. To create a session variable.
[/quote]


Yea didnt orginally have that in there but that dosent make a difference anyway.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users