dennismonsewicz Posted December 6, 2007 Share Posted December 6, 2007 Ok... I have this login script: <?php //page title: checklogin.php ob_start(); include "includes/db_login.php"; // username and password sent from signup form $username = $_POST['username']; $password = $_POST['password']; $userid = $_POST['userid']; $sql="SELECT * FROM users WHERE username='$username' and password='$password' and userid='$userid'"; $result=mysql_query($sql) or die(mysql_error()); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ // Register $username, $password and redirect to file "login_success.php" session_register("username"); session_register("password"); header("location:../index.php"); } else { include "includes/header.php"; echo "<p>Wrong Username or Password</p>"; include "includes/footer.php"; } ob_end_flush(); ?> The information being pulled from this script is on this page: <?php include "includes/header.php"; //page title: login_index.php ?> <p>To login, please fill out the form below with your given username and password</p> <div id="loginform"> <form name="form1" method="post" action="checklogin.php"> <table border="0" cellpadding="0" cellspacing="0" align="center"> <tr> <td>Username: </td> <td><input name="username" type="text" id="username" /></td> </tr> <tr> <td>Password: </td> <td><input name="password" type="password" id="password" /></td> </tr> <tr> <td colspan="2"><input type="image" src="../images/login.gif" class="submit" alt="Submit Changes" value="Login" /></td> </tr> </table> </form> </div> <?php include "includes/footer.php"; ?> Now here is my question: I want to be able to transfer the username to the my header.php file which is an include for the main site. Right now I have a logout button. Well in parenthesis right beside the logout button I want to put the username that is logged in. How do I pass the username and rowid variable from the checklogin.php to header.php? header.php looks like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Intranet</title> <link href="/styles.css" rel="stylesheet" type="text/css" /> </head> <body> <?PHP session_start(); if(!session_is_registered(username)){ header("location:login/index.php") } ?> <a name="top"></a> <div id="header"> <div id="logout" style="float: right; margin-right:50px; margin-top: 20px;"><a href="http://intranet.healthresources.net/login/logout.php">Logout? <?php echo "(" . $username . ")" ?></a></div> ?> Link to comment https://forums.phpfreaks.com/topic/80483-login-script/ Share on other sites More sharing options...
adam291086 Posted December 6, 2007 Share Posted December 6, 2007 when a user logs in, you can set that information into a session. Then call on that session in the header.php. <?php $_SESSION['username'] = $row['user_id']; ?> user id come from a database search. Link to comment https://forums.phpfreaks.com/topic/80483-login-script/#findComment-408026 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.