Displaying member name on restricted page
I am creating a project in PHP where there are some pages which can be visited by selected members only and if any unrestricted user or member visit that page then his name should get displayed on those restricted pages. I have ask my friends about the same, they told me that it's being possible but don't know about the coding. Can anyone help me out with this issue.
Displaying member name on restricted page
Yes if you want you can display member name on restricted page for that you need to use the following coding.
PHP Code:
[code=php]
<?php
session_start();
include("cn.php");
$msg = "";
if (isset($_POST['Submit']))
{
$username = $_POST['pfno'];
$password = $_POST['ledgerno'];
$result = mysql_query("Select * From user_table where pfno='$pfno'",$link);
{
if($ledgerno == $row["ledgerno"])
{
$_SESSION['adminok'] = "ok";
$_SESSION['pfno'] = "pfno";
$_SESSION['ledgerno'] = "ledgerno";
$_SESSION['valid_time']=time();
header("Location: Members_Area.php?pfno=".$_SESSION['pfno']);
}
else
{
$msg = "ledgerno incorrect";
}
}
{
$msg = "pfno incorrect";
}
}
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>
<body>
<table width="200" border="0" align="center" cellpadding="1" cellspacing="2" bgcolor="blue">
<tr>
<form name="form_1" method="post" action="">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="blue">
<tr>
<td colspan="3"><strong>Members Login </strong></td>
</tr>
<tr>
<td width="78">PF Number </td>
<td width="6">:</td>
<td width="294"><input name="pfno" type="text" id="pfno"></td>
</tr>
<tr>
<td>Ledger Number</td>
<td>:</td>
<td><input name="ledgerno" type="password" id="ledgerno"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>[/code]
members_area
[code=php]<?php
session_start();
if (!$_SESSION["pfno"])
{
header("Location:Login.php");
}
include("cn.php");
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LIST OF MEMBERS</title>
</head>
<body>
<a href="Members_Area.php">Members Area</a> | <a href="Edit_Profile.php">Edit Profile</a> | <a href="Reports.php">Reports</a> | <a href="Logout.php">Logout</a>
<?php
$pfno=$_GET["pfno"];
$result=mysql_query("Select * From user_table where pfno='$pfno'") or die (mysql_error());
$user = mysql_fetch_assoc($result);
echo mysql_num_rows($result);
echo ("<p>Welcome user" .$user["pfno"]);
echo ("<p>Logged in: " .date("m/d/Y", $_SESSION["valid_time"]));
?>
</body>
</html>
[/code]
Displaying member name on restricted page
I have try to use the above code on my web page but was not able to display member name on restricted page. Can anyone tell me where Modifier has made any mistake and thanks for replying me. With you code i am able to make some similar type of code.
Displaying member name on restricted page
It seems that SQL query which you are using is not proper as the variable pfno is not set before being passed into the query you can have a check over here
PHP Code:
username = $_POST['pfno'];
$password = $_POST['ledgerno'];
$result = mysql_query("Select * From user_table where pfno='$pfno'",$link);
According to me the SQL query should be as follows
PHP Code:
$result = mysql_query("Select * From user_table where pfno='$username'",$link);
If you want you can store many information in PHP session, if you authenticate the user you can store his name as well in the session too.