March 26, 200917 yr Hi All, After a user logs into my website, i would like to echo there name. I know you post and get from one page to another, but i have a page in the middle that validates there login. this is my logon form so far: <form action="<?php echo $loginFormAction; ?>" method="post" id="authorisation-check"> <table width="400" border="0" align="center" cellpadding="3" cellspacing="0" class="table" id="table"> <tr> <th class="aligncenter whitetext" colspan="2">Please Enter Your Username And Password</th> </tr> <tr> <th align="right" class="spec">Username:</th> <td align="left"><input type="text" name="username" id="username" /></td> </tr> <tr> <th align="right" class="specalt">Password:</th> <td align="left"><input name="password" type="password" id="password" /></td> </tr> <tr> <th align="right" class="spec"> </th> <td align="left"><input name="Submit" type="submit" class="button" value="Login" /></td> </tr> </table> </form> If their login details are correct it forwards them to a menu.
March 26, 200917 yr You could send the username in the URL and then use the $_GET method on the other page to find out what the username is.
March 26, 200917 yr On the page where you process their log in , assign session variables for that user. You can then access the $_SESSION array on other pages.
March 26, 200917 yr Author i lied there is only two pages: login.php and menu.php but instead of the form on login.php posting to menu.php it does the following: <form action="<?php echo $loginFormAction; ?>" method="post" id="authorisation-check"> $loginFormAction is on the same page. <?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 = "login.php"; $MM_redirecttoReferrer = false; mysql_select_db($database, $connection); $LoginRS__query=sprintf("SELECT username, password FROM users_tbl WHERE username=%s AND password=%s", GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); $LoginRS = mysql_query($LoginRS__query, $connection) 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 ); } } ?>
March 27, 200917 yr just set a session somewhere $_SESSION['name'] = $_POST['name']; echo $_SESSION['name']
Create an account or sign in to comment