12-31-2009, 09:04 AM
Hello SF
I was creating my first website using php and i was doing great gathering the codes from here SF and from different tut around the internet.
I have created the database and the tables, the register page and the login page and everything is fine for now.
But after that i can't find how to show someone my username after i have logged in.
for example i need to see my username somewhere in the index.php page and i really appreciate if anybody can help me with the code.
Here are the codes:
login.php
login.details.php
Anybody can help me with the code please
thanks
I was creating my first website using php and i was doing great gathering the codes from here SF and from different tut around the internet.
I have created the database and the tables, the register page and the login page and everything is fine for now.
But after that i can't find how to show someone my username after i have logged in.
for example i need to see my username somewhere in the index.php page and i really appreciate if anybody can help me with the code.
Here are the codes:
login.php
PHP Code:
<?php
session_start();
?>
<html>
<head>
<title>empty</title>
<meta name="keywords" content="empty">
<meta name="description" content="empty">
<link rel="shortcut icon" href="empty/favicon.ico">
<link href="empty/css_style.css" rel="stylesheet" type="text/css">
</head>
<body style="background:url('empty/img1.gif');" leftmargin="10" topmargin="10">
<table border="1" cellspacing="0" cellpadding="0" height="150" width="100%" bordercolor="#aabbbb">
<tr>
<td>
<?php include("header1.php"); ?>
</td>
</tr>
<tr>
<td>
<?php include("header2.php"); ?>
</td>
</tr>
<tr>
<td>
<?php include("header3.php"); ?>
</td>
</tr>
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0" height="100%" width="100%">
<tr>
<td style="background:#ffffff">
<?php include("mysql.php"); ?>
<form id="register" action="login.details.php" method="POST">
<table border="0" cellspacing="0" cellpadding="0" height="100%" width="30%" align="center">
<tr><td><font color="#000000">Username:</font></td><td><input type="text" name="loginusername" id="loginusername"/></td></tr>
<tr><td><font color="#000000">Password:</font></td><td><input type="password" name="loginpassword" id="loginpassword"/></td></tr>
<tr><td></td><td><input type="submit" value="Login" name="loginsubmit" id="loginsubmit" /></td></tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php include("buttom1.php"); ?>
</td>
</tr>
</table>
</body>
</html>
login.details.php
PHP Code:
<?php
session_start();
include("mysql.php");
$loginusername=$_POST['loginusername'];
$loginpassword=$_POST['loginpassword'];
// to protect from sql injection we use these
$loginusername = stripslashes($loginusername);
$loginpassword = stripslashes($loginpassword);
$loginusername = mysql_real_escape_string($loginusername);
$loginpassword = mysql_real_escape_string($loginpassword);
$checkuserdetailsexistance = mysql_num_rows(mysql_query("select * from Users where Username='$loginusername' and Password='$loginpassword'"));
if ($checkuserdetailsexistance == 1)
{
session_register("loginusername");
session_register("loginpassword");
header("location: index.php");//this is the page you want your login to goto so change the index.php part
}
else {
echo "Login failed. If you are not a member yet, please signup. Otherwise, check your spelling and login again.";
}
?>
Anybody can help me with the code please
thanks