bcraig Posted May 3, 2006 Share Posted May 3, 2006 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?><?phpecho 'Welcome to my website '.$_SESSION['username'];?><?phpmysql_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)); ?><?phpmysql_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] Quote Link to comment https://forums.phpfreaks.com/topic/8940-sessions/ Share on other sites More sharing options...
.josh Posted May 3, 2006 Share Posted May 3, 2006 try taking out the $ in session_register("[!--coloro:red--][span style=\"color:red\"][!--/coloro--]$[!--colorc--][/span][!--/colorc--]username"); Quote Link to comment https://forums.phpfreaks.com/topic/8940-sessions/#findComment-32854 Share on other sites More sharing options...
bcraig Posted May 3, 2006 Author Share Posted May 3, 2006 [!--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 :( Quote Link to comment https://forums.phpfreaks.com/topic/8940-sessions/#findComment-32855 Share on other sites More sharing options...
wildteen88 Posted May 3, 2006 Share Posted May 3, 2006 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 Link to comment https://forums.phpfreaks.com/topic/8940-sessions/#findComment-32888 Share on other sites More sharing options...
bcraig Posted May 4, 2006 Author Share Posted May 4, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/8940-sessions/#findComment-33210 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.