lewis987 Posted May 14, 2007 Share Posted May 14, 2007 ok, i have a login script that when logged in, it shows the user ID, username and time logged in but the problem is, when i log in, it doesnt show the User ID, ive tried with 4 accounts and having no luck. The file code is posted below: LOGIN.PHP <?php session_start(); // dBase file include "dbcon.php"; if ($_GET["op"] == "login") { if (!$_POST["username"] || !$_POST["password"]) { die("You need to provide a username and password."); } // Create query $q = "SELECT * FROM `users` " ."WHERE `username`='".$_POST["username"]."' " ."AND `password`=PASSWORD('".$_POST["password"]."') " ."LIMIT 1"; // Run query $r = mysql_query($q); if ( $obj = mysql_fetch_object($r) ) { // Login good, create session variables $_SESSION["valid_id"] = $obj->id; $_SESSION["valid_user"] = $_POST["username"]; $_SESSION["valid_time"] = time(); // Redirect to member page Header("Location: members.php"); } else { // Login not successful die("Sorry, could not log you in. Wrong login information."); } } else { //If all went right the Web form appears and users can log in echo "<form action=\"?op=login\" method=\"POST\">"; echo "Username: <input name=\"username\" size=\"15\"><br />"; echo "Password: <input type=\"password\" name=\"password\" size=\"8\"><br />"; echo "<input type=\"submit\" value=\"Login\">"; echo "</form>"; echo "<br /><br /><br />"; echo "<a href=\"reg.php\">Register Now!</a>"; } ?> MEMBERS.PHP <?php session_start(); if (!$_SESSION["valid_user"]) { // User not logged in, redirect to login page Header("Location: login.php"); } // Member only content // ... // ... // ... // Display Member information echo "<p>User ID: " . $_SESSION["valid_id"]; echo "<p>Username: " . $_SESSION["valid_user"]; echo "<p>Logged in: " . date("m/d/Y", $_SESSION["valid_time"]); // Display logout link echo "<p><a href=\"logout.php\">Click here to logout!</a></p>"; ?> try it at: scoop987.homeftp.net/test/login/login.php Link to comment https://forums.phpfreaks.com/topic/51371-solved-session-error/ Share on other sites More sharing options...
lewis987 Posted May 14, 2007 Author Share Posted May 14, 2007 solved myself! Link to comment https://forums.phpfreaks.com/topic/51371-solved-session-error/#findComment-252973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.