Jump to content

sessions


bcraig

Recommended Posts

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
[code]<?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);
?>[/code]

login.php
[code]<?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>[/code]
Link to comment
Share on other sites

[!--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) [snapback]370797[/snapback][/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 :(
Link to comment
Share on other sites

[!--quoteo(post=370832:date=May 3 2006, 06:11 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ May 3 2006, 06:11 AM) [snapback]370832[/snapback][/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.
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.