Kunkka Posted June 4, 2009 Share Posted June 4, 2009 its not working. can someone help me. i want to see the username which logs in the login page in the home.php i really dont know y? but even without the proper details in the login form it directs to home page. can somebody help me with that <?php if(!isset($_SESSION)) { session_start(); } ?> <html> <head> <style type="text/css" media="all"> @import "css/stylemaster.css"; </style> <title>Online Examination</title> </head> <body> <div id="page-container"> <div id="header"><h1> </h1> </div> <div id="main-nav">Main Nav</div> <div id="sidebar-a" > <font class="ws8" color="#FF9900" face="Tahoma"></font> <?php echo "Welcome <br><br> ".$_SESSION['username']; // prints something like: Wednesday the 15th echo date("l \\t\h\e jS"); ?> </div> <div id="content">Content Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam gravida enim ut risus. Praesent sapien purus, ultrices a, varius ac, suscipit ut, enim. Maecenas in lectus. Donec in sapien in nibh rutrum gravida. Sed ut mauris. Fusce malesuada enim vitae lacus euismod vulputate. Nullam rhoncus mauris ac metus. Maecenas vulputate aliquam odio. Duis scelerisque justo a pede. Nam augue lorem, semper at, porta eget, placerat eget, purus. Suspendisse mattis nunc vestibulum ligula. In hac habitasse platea dictumst. <h2>About</h2> <p><strong>Enlighten Designs</strong> is an Internet solutions provider that specialises in front and back end development. To view some of the web sites we have created view our portfolio.</p> <p>We are currently undergoing a 'face lift', so if you have any questions or would like more information about the services we provide please feel free to contact us.</p> <h2>Contact Us</h2> <p>Phone: (07) 853 6060<br /> Fax: (07) 853 6060<br /> Email: <a href="mailto:[email protected]">[email protected]</a><br /> P.O Box: 14159, Hamilton, New Zealand</p> <p><a href="#">More contact information...</a></p> </div> <div id="footer"><div id="altnav"> <a href="#">About</a> - <a href="#">Services</a> - <a href="#">Portfolio</a> - <a href="#">Contact Us</a> - <a href="#">Terms of Trade</a> </div> Copyright © Enlighten Designs <br/> Powered by <a href="http://www.enlightenhosting.com/">Enlighten Hosting</a> and <a href="http://www.vadmin.co.nz/">Vadmin 3.0 CMS</a> </div> </div> </body> </html> here is my login page <?php require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php"); $connection= @mysql_connect($db_host,$db_user,$db_password) or die("Error Connecting"); mysql_select_db($db_name,$connection); if (isset($_POST["username"]) && isset($_POST["password"])) { $username = mysql_real_escape_string($_POST["username"]); $password = mysql_real_escape_string($_POST["password"]); $query = "SELECT * FROM login WHERE Username='$username' and Password='$password'"; echo ($query); $results = mysql_query($query);if(mysql_num_rows($results) == 1) { $_SESSION['username'] = $_REQUEST['username']; $_SESSION['password'] = $_REQUEST['password']; header("Location: home.php"); } else { echo '<script type=""text/javascript""> alert("Access Denied! Incorrect Username or Password") </script>'; } } ?> <head> <style type="text/css" media="all"> @import "css/stylemaster.css";.style1 {font-size: 10px} .style3 {font-size: 10px; font-weight: bold; } .style4 {color: #FFFFFF} body { background-color: #FFFFFF; } </style> </head> <body> <div id="page-container"> <div id="header"><h1> </h1> </div> <div id="main-nav">Main Nav</div> <div id="sidebar-a"> <form id="form1" name="form1" method="post" action="home.php"> <h3 class="style1">>> Login </h3> <pre>User Type : <select name="usertype" size="1" id="usertype"> <option selected="selected">Student</option> <option>Lectuerer</option> <option>Administrator</option> </select> </pre> <pre>User Name: <input name="username" type="text" id="username" value="" size="12px" /> </pre> <pre>Password : <input type="password" name="password" id="password" size="12px"/> </pre> <pre> <input type="submit" name="Login" value="Submit" /> </pre> <p>Not a member yet?<br> <a href="register.php">Register Now!</a></p> <p> </p> </form> </div> </body> Link to comment https://forums.phpfreaks.com/topic/160857-my-session_starts-not-working/ Share on other sites More sharing options...
gevans Posted June 4, 2009 Share Posted June 4, 2009 session_start(); needed on the login page http://www.phpfreaks.com/forums/index.php/topic,37442.0.html llok at the if/when you get header errors Link to comment https://forums.phpfreaks.com/topic/160857-my-session_starts-not-working/#findComment-848944 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.