Hi,
I got the page login.php that have a script that logs you in and then go to loggedin.php with a piece of code to validate your loged in.
The validate stores the username, how can I echo the username out onto the page?
Login.php
[PHP]
<?php
session_start();
// dBase file
$con = mysql_connect("www.seeandsee.co.za","seej","jas654 ");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("regsvqs", $con);
if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
{
die("You need to provide a username and password.");
}
// Create query
$q = "SELECT * FROM `details` "
."WHERE `a`='".$_POST["username"]."' "
."AND `b`='".$_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: /vqs/register/loggedin.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><a href=\"pass.php\">forgot password? </a>";
}
?>
[/PHP]
loggedin.php
[PHP]
<?php
session_start();
if (!$_SESSION["valid_user"])
{
// User not logged in, redirect to login page
Header("Location: index.php");
}
?>
[/PHP]