marquel2k69 Posted May 29, 2012 Share Posted May 29, 2012 I was able to get my login script working thanks for the suggestions, now that I'm able to log in how do I display Welcome $username to the header of the home page here is my login script <?php $errorMsg = ''; $username = ''; $password = ''; if (isset($_POST['username'])) { $username = $_POST['username']; $password = $_POST['password']; $remember = $_POST['remember']; $username = stripslashes($username); $password = stripslashes($password); $username = strip_tags($username); $password = strip_tags($password); // error handling conditional checks go here if ((!$username) || (!$password)) { $errorMsg = 'Username and Password fields can not be empty!'; } else { // Error handling is complete so process the info if no errors include 'scripts/connect_to_mysql.php'; // Connect to the database $username = mysql_real_escape_string($username); // After we connect, we secure the string before adding to database $password = mysql_real_escape_string($password); // After we connect, we secure the string before adding to database $password = md5($password); // Add MD5 Hash to the password variable they supplied after filtering it // Make the SQL query $sql = mysql_query("SELECT * FROM myMembers WHERE username='$username' AND password='$password' AND email_activated='1'"); $login_check = mysql_num_rows($sql); // If login check number is greater than 0 (meaning they do exist and are activated) if($login_check > 0){ while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $_SESSION['id'] = $id; $username = $row["username"]; $_SESSION['username'] = $username; $firstname = $row["firstname"]; $_SESSION['firstname'] = $firstname; mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id' LIMIT 1"); } // close while // Remember Me Section if($remember == "yes"){ setcookie("idCookie", $id, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days } // All good they are logged in, send them to homepage then exit script header("location: index.php"); exit(); } else { // Run this code if login_check is equal to 0 meaning they do not exist $errorMsg = "Username or Password incorrect, please try again"; } } // Close else after error checks } //Close if (isset ($_POST['username'])){ ?> and here is the header that I want the Welcome $username script to output to <link href="style/main.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style6 {font-size: 16px} .style7 {font-size: 18px} --> </style> <table width="950" align="center" cellpadding="0" style="height:100px; background-image:url(style/header.jpg); background-repeat:no-repeat;"> <tr> <td colspan="2"><p><span class="style6"><a href="register.php">Register an Account</a></span></p> </td> <td colspan="5" class="blueColor style7"></td> <td rowspan="2"><div align="center"><a href="#" class="style6">Log Out </a></div></td> </tr> <tr> <td colspan="7"><a href="login.php" class="style6">Log In </a></td> </tr> <tr> <td width="111"><div align="center"></div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com">HOME</a></div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/my_account.php">MY ACCOUNT</a> </div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/how_it_works.php">HOW IT WORKS</a> </div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/contact_us.php">CONTACT US </a></div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/about.php">ABOUT</a></div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/faq.php">FAQ</a></div></td> <td width="111"> </td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/263344-welcome-text/ Share on other sites More sharing options...
Adam Posted May 29, 2012 Share Posted May 29, 2012 Their username is stored in $_SESSION['username']. I'm assuming you have session_start() in your script and have verified they're logged in before you're trying to display it? Quote Link to comment https://forums.phpfreaks.com/topic/263344-welcome-text/#findComment-1349614 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.