Hi everyone i'm having a problem with my login system and really hope someone can help me out here..
I made a login page and it's all working and it perfectly connect to my database but I also want the option when someone logins that they see a welcome message on each page on the website like "Welcome, $username"
I searched on google but each time i pumb into errors
I would like to show the "welcome message" in the header.
Below you can see my code:
Home.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="Design.css">
<title>Fotoalbum</title>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id ="Wrapper">
<div id ="Logo">
<img src="Afbeeldingen/10881558_759342210782402_1567173209848574625_n.jpg" width="160" height="150" />
</div>
<div id ="Header">
<center>
<p> </p>
<H1><p>CB </p></H1>
</center>
<a href="Main_login.php">Login</a>
<a href="Logout.php">Logout</a>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Biografie</a></li>
<li><a href="#">Fotoalbum</a></li>
<li><a href="#">Contact</a></li>
</ul>
</center>
</div>
</body>
</html>
Main_LoginForm.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Main Login</title>
</head>
<body>
<form action="Inlog.php" method="post">
<label>UserName :</label>
<input type="text" name="Naam"/><br />
<label>Password :</label>
<input type="password" name="Wachtwoord"/><br/>
<p>
<input type="submit" value=" Submit "/><br />
</form>
</body>
</html>
Inlog.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
ob_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="InlogFA"; // Database name
$tbl_name="InlogFotoalbum"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['Naam'];
$mypassword=$_POST['Wachtwoord'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE Naam='$myusername' and Wachtwoord='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['myusername']= "myusername";
$_SESSION['mypassword']= "mypassword";
header("Location: Login_success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
</body>
</html>
Login_succesful.php
<?php
session_start();
if(!$_SESSION['myusername']){
header("Location: Fotoalbum.php");
}
?>
<body>
Login Succesful!
</body>
</html>