I have created the following page which once a successful login has happened 2 session variables are created and then on the next page I try to call these 2 session variables but it just doesn’t seem to work.
I am stuck as to what to do now as it looks to be coded correctly (I think)
Thank You for any help
Code:<?PHP $username = ($_POST['username']); $password = ($_POST['password']); $encrypted_password=md5($password); //check that the user is calling the page from the login form and not accessing it directly //and redirect back to the login form if necessary if (!isset($username) || !isset($password)) { header( "Location: index.php" ); } //check that the form fields are not empty, and redirect back to the login page if they are elseif (empty($username) || empty($password)) { header( "Location: index.php" ); } else{ //create or open database $db = sqlite_open("C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/swiftdist/website/database/distributorlogin.db") or die("failed to open the database"); //get info $result = sqlite_query($db, "SELECT * FROM tbllogin where username = '$username' and password = '$encrypted_password'"); //check that at least one row was returned $rowCheck = sqlite_num_rows($result); if($rowCheck > 0){ while($row = sqlite_fetch_array($result)){ //start the session and register a variable session_start(); $_SESSION["username"] = $result['username']; $_SESSION["timestamp"] = $result['timestamp']; header( "Location: loginsuccess.php" ); } } else { //if nothing is returned by the query, unsuccessful login code goes here... $loginfailure = "Sorry you have neterd an incorrect username or password. Please try agaian or contact us for your login details."; } } ?>
Code:<?php session_start(); if(!isset($_SESSION["username"])){ header ( 'location: index.php' ); exit; } else { $logintext = "Welcome to the site " . $_SESSION["username"] . " The last time you were here was " . $_SESSION["timestamp"] . ""; } ?>
When i login correctly and view the page the only outcome i get is
It doesn't seem to output the timestamp session variable.Welcome to the site test The last time you were here was
Cheesr









Bookmarks