tobimichigan Posted August 4, 2009 Share Posted August 4, 2009 Hello again coe gurus, Please I need help in displaying the login value on the 1st page of the current user which I want to be the 1st step in extracting relevant information for the user. Here's my login script: Login.php <?php session_start(); include("cn.php"); $msg = ""; //require_once('actions/'.$action.'.php'); if (isset($_POST['Submit'])) { $username = $_POST['pfno']; $password = $_POST['ledgerno']; $result = mysql_query("Select * From user_table where pfno='$username'",$link); //if(mysql_num_rows($result)>0) { //$row = mysql_fetch_array($result, MYSQL_BOTH); if($ledgerno == $row["ledgerno"]) { $_SESSION['adminok'] = "ok"; $_SESSION['pfno'] = "username"; $_SESSION['ledgerno'] = "ledgerno"; $_SESSION['valid_time']=time(); header("Location: Members_Area.php?pfno=".$_SESSION['pfno']); } else { $msg = "ledgerno incorrect"; } } //else { $msg = "pfno incorrect"; } } ?> <!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>Login</title> </head> <body> <div align="center"><img src="../../images/LasustaffCoop2.jpg" alt="" name="LasuStaffCams_Logo" width="700" height="150" id="LasuStaffCams_Logo" /></div> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action=""> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Members Logon </strong></td> </tr> <tr> <td width="78">PF NO. </td> <td width="6">:</td> <td width="294"><input name="username" type="text" id="pfno"></td> </tr> <tr> <td>LEDGER NO. </td> <td>:</td> <td><input name="password" type="password" id="ledgerno"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Login"></td> </tr> </table> </td> </form> Members_Area.php <?php session_start(); if (!$_SESSION["pfno"]) { //user not logged in, redirect to login page header("Location:Login.php"); } include("cn.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>LASUSTAFFCAMS 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 echo "Welcome $logged $_SESSION[pfno]<br><br>"; //$pfno=$_GET["pfno"]; //$result=mysql_query("Select * From user_table where pfno='$username'") or die (mysql_error()); //$result=mysql_query($query,$link; //$pfno = mysql_fetch_assoc($result); //echo mysql_num_rows($result); //Display Member Information //print $pfno //echo ("<p>Welcome User:" .$username["pfno"]); //echo ("<p>Welcome: ".trim($_SESSION['username'])); echo ("<p>Logged in: " .date("m/d/Y", $_SESSION["valid_time"])); ?> </body> </html> this-><p>Welcome: ".trim($_SESSION['username'])); code is the one responsible 4 displaying the current user data...but on logon it seems to display either nothing or just username rather than the actual 4 digit value in the pfno column. Please any sharp pointer would be welcomed. Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/ Share on other sites More sharing options...
premiso Posted August 4, 2009 Share Posted August 4, 2009 I would recommend a better test to see if that session value isset: if (!isset($_SESSION["pfno"])) That way you can be sure it had to be set and not just returning cause the value was false. As far as anything else, I really cannot see where it may be going wrong. Try that and see if it helps the problem. Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890806 Share on other sites More sharing options...
Bjom Posted August 4, 2009 Share Posted August 4, 2009 I cannot see you set $_SESSION['username'] anywhere... Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890808 Share on other sites More sharing options...
premiso Posted August 4, 2009 Share Posted August 4, 2009 I cannot see you set $_SESSION['username'] anywhere... It is amazing how someone pointing out something makes you see more items: $_SESSION['pfno'] = "username"; You set pfno to be "username" instead of this 4 code you wanted it to be. That may be a place to start, also see Bjom's comment about the setting of session username. Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890813 Share on other sites More sharing options...
tobimichigan Posted August 4, 2009 Author Share Posted August 4, 2009 I cannot see you set $_SESSION['username'] anywhere... It is amazing how someone pointing out something makes you see more items: $_SESSION['pfno'] = "username"; You set pfno to be "username" instead of this 4 code you wanted it to be. That may be a place to start, also see Bjom's comment about the setting of session username. Bjom n Premiso, here's my modified code: 1. Login <?php session_start(); include("cn.php"); $msg = ""; //require_once('actions/'.$action.'.php'); if (isset($_POST['Submit'])) { $username = $_POST['pfno']; $password = $_POST['ledgerno']; $result = mysql_query("Select * From user_table where pfno='$username'",$link); //if(mysql_num_rows($result)>0) { //$row = mysql_fetch_array($result, MYSQL_BOTH); if($ledgerno == $row["ledgerno"]) { $_SESSION['adminok'] = "ok"; $_SESSION['pfno'] = "pfno"; $_SESSION['username'] = "username"; $_SESSION['ledgerno'] = "ledgerno"; $_SESSION['valid_time']=time(); header("Location: Members_Area.php?pfno=".$_SESSION['pfno']); } else { $msg = "ledgerno incorrect"; } } //else { $msg = "pfno incorrect"; } } ?> <!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>Login</title> </head> <body> <div align="center"><img src="../../images/LasustaffCoop2.jpg" alt="" name="LasuStaffCams_Logo" width="700" height="150" id="LasuStaffCams_Logo" /></div> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action=""> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Members Logon </strong></td> </tr> <tr> <td width="78">PF NO. </td> <td width="6">:</td> <td width="294"><input name="pfno" type="text" id="pfno"></td> </tr> <tr> <td>LEDGER NO. </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> 2. Members.php <?php session_start(); if (!$_SESSION["pfno"]) if (!$_SESSION["username"]) if (!$_SESSION["ledgerno"]) //user not logged in, redirect to login page header("Location:Login.php"); include("cn.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>LASUSTAFFCAMS 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 echo ("<p>Welcome PFNO:" .trim($_SESSION['pfno'])); //$pfno=$_GET["pfno"]; //$result=mysql_query("Select * From user_table where pfno='$username'") or die (mysql_error()); //$result=mysql_query($query,$link; //$pfno = mysql_fetch_assoc($result); //echo mysql_num_rows($result); //Display Member Information //print $pfno //echo ("<p>Welcome User:" .$username["pfno"]); //echo ("<p>Welcome: ".trim($_SESSION['username'])); echo ("<p>Logged in: " .date("m/d/Y", $_SESSION["valid_time"])); ?> </body> </html> I introduced <?php $_SESSION['username']="username" into login.php and <?php if !$_SESSION['username']="username" to members.php The output is as follows: Members Area | Edit Profile | Reports | Logout Welcome PFNO:pfno <-this Logged in: 08/04/2009 The problem still remains pfno. Where PFNO outputs "pfno", is the problem.This ought to be a stored procedure precisely a 4 (say 1234) digit used at the point of registering not pfno which is the name of the column. Please code gurus try harder and help me solve this imbroglio. Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890882 Share on other sites More sharing options...
Bjom Posted August 4, 2009 Share Posted August 4, 2009 ?try harder? $_SESSION['pfno'] = "pfno"; $_SESSION['username'] = "username"; as premiso already pointed out... this might be problematic. Try hard and answer: What do these two lines of code exactly do? Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890890 Share on other sites More sharing options...
tobimichigan Posted August 4, 2009 Author Share Posted August 4, 2009 I would recommend a better test to see if that session value isset: if (!isset($_SESSION["pfno"])) That way you can be sure it had to be set and not just returning cause the value was false. As far as anything else, I really cannot see where it may be going wrong. Try that and see if it helps the problem. Premiso, please where did you say I should put if (!isset($_SESSION["pfno"])), on the login or on the member? Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890906 Share on other sites More sharing options...
premiso Posted August 4, 2009 Share Posted August 4, 2009 Members Area: <?php session_start(); if (!$_SESSION["pfno"]) { //user not logged in, redirect to login page header("Location:Login.php"); } include("cn.php"); ?> Change that if statement to the isset. Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890932 Share on other sites More sharing options...
tobimichigan Posted August 4, 2009 Author Share Posted August 4, 2009 Members Area: <?php session_start(); if (!$_SESSION["pfno"]) { //user not logged in, redirect to login page header("Location:Login.php"); } include("cn.php"); ?> Change that if statement to the isset. Check out my modification: Login code: <?php session_start(); include("cn.php"); $msg = ""; //require_once('actions/'.$action.'.php'); if (isset($_POST['Submit'])) { $username = $_POST['pfno']; $password = $_POST['ledgerno']; $result = mysql_query("Select * From user_table where pfno='$username'",$link); //if(mysql_num_rows($result)>0) { //$row = mysql_fetch_array($result, MYSQL_BOTH); if($ledgerno == $row["ledgerno"]) { $_SESSION['adminok'] = "ok"; $_SESSION['pfno'] = "pfno"; //$_SESSION['username'] = "username"; $_SESSION['ledgerno'] = "ledgerno"; $_SESSION['valid_time']=time(); header("Location: Members_Area.php?pfno=".$_SESSION['pfno']); } else { $msg = "ledgerno incorrect"; } } //else { $msg = "pfno incorrect"; } } ?> <!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>Login</title> </head> <body> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action=""> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Members Logon </strong></td> </tr> <tr> <td width="78">PF NO. </td> <td width="6">:</td> <td width="294"><input name="pfno" type="text" id="pfno"></td> </tr> <tr> <td>LEDGER NO. </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> 2. Member <?php session_start(); if($_SESSION["pfno"]=="") { header("location: Login.php"); } include("cn.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>LASUSTAFFCAMS 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 echo "<p>Welcome User : ".$_SESSION["pfno"]. "<p>Logged in: " .date("m/d/Y", $_SESSION["valid_time"]); ?> </body> </html> As u can see 4 d Login.php <?php //$_SESSION['username'] = "username";?> has been eliminated I'm now left with the <?php $_SESSION['pfno'] = "pfno";?> and in the Member page: <?php session_start(); if($_SESSION["pfno"]=="") { header("location: Login.php"); } include("cn.php"); ?> Yet the pfno still appears as the pfno instead of the value in the base.. Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890952 Share on other sites More sharing options...
Bjom Posted August 4, 2009 Share Posted August 4, 2009 if you would actually read please: $_SESSION['pfno'] = "pfno"; What does that line of code do? And what do you want it to do? Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890954 Share on other sites More sharing options...
tobimichigan Posted August 5, 2009 Author Share Posted August 5, 2009 if you would actually read please: $_SESSION['pfno'] = "pfno"; What does that line of code do? And what do you want it to do? In the Members page echo "<p>Welcome User : ".$_SESSION["pfno"]. "<p>Logged in: " .date("m/d/Y", $_SESSION["valid_time"]); simply refers to the authenticated member who is to get the exact pf 4 digits entered on the html-form. That's it's meant to do..except if I'm missing something. Then in the login, $_SESSION['pfno'] = "pfno"; its meant to enable of as a session variable. Is there something I'm still doing wrong here?? Please let me know... Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-890991 Share on other sites More sharing options...
Bjom Posted August 5, 2009 Share Posted August 5, 2009 You assign the string value "pfno" to the variable $_SESSION['pfno']; So when you read it out - it show exactly that: "pfno"... You need at some place assign this 4 digit number to the variable $_SESSION['pfno'];, but you don't. same problem existed with $_SESSION['username'] = "username"; <-- this will always show the string "username"... Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-891147 Share on other sites More sharing options...
tobimichigan Posted August 5, 2009 Author Share Posted August 5, 2009 You assign the string value "pfno" to the variable $_SESSION['pfno']; So when you read it out - it show exactly that: "pfno"... You need at some place assign this 4 digit number to the variable $_SESSION['pfno'];, but you don't. same problem existed with $_SESSION['username'] = "username"; <-- this will always show the string "username"... So then, B, what do u suggest or what better ideas do u have? Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-891152 Share on other sites More sharing options...
Bjom Posted August 5, 2009 Share Posted August 5, 2009 where do you have the pfno stored? do you have it available in any variable? then assign that variable to the session variable. As for username: $_SESSION['username'] = $username; should do the trick (unless the $username variable contains the pfno, then change the above line accordingly) Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-891160 Share on other sites More sharing options...
tobimichigan Posted August 5, 2009 Author Share Posted August 5, 2009 where do you have the pfno stored? do you have it available in any variable? then assign that variable to the session variable. As for username: $_SESSION['username'] = $username; should do the trick (unless the $username variable contains the pfno, then change the above line accordingly) Bj, u've just saved the day!!!! Wow, have been working on this University Project for like 4 days now without idea what I could be doing wrong, but alas! You just hit the nail on the head. Here's the corrected code: Login.php <?php session_start(); include("cn.php"); $msg = ""; //require_once('actions/'.$action.'.php'); if (isset($_POST['Submit'])) { $username = $_POST['pfno']; $password = $_POST['ledgerno']; $result = mysql_query("Select * From user_table where pfno='$username'",$link); //if(mysql_num_rows($result)>0) { //$row = mysql_fetch_array($result, MYSQL_BOTH); if($ledgerno == $row["ledgerno"]) { $_SESSION['adminok'] = "ok"; //$_SESSION['pfno'] = "$pfno"; $_SESSION['pfno'] = "$username"; $_SESSION['ledgerno'] = "$ledgerno"; $_SESSION['valid_time']=time(); header("Location: Members_Area.php?pfno=".$_SESSION['pfno']); } else { $msg = "ledgerno incorrect"; } } //else { $msg = "pfno incorrect"; } } ?> <!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>Login</title> </head> <body> <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action=""> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"><strong>Members Logon </strong></td> </tr> <tr> <td width="78">PF NO. </td> <td width="6">:</td> <td width="294"><input name="pfno" type="text" id="pfno"></td> </tr> <tr> <td>LEDGER NO. </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> Members.php <?php session_start(); if($_SESSION["pfno"]=="") { header("location: Login.php"); } include("cn.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> 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()); $pfno = mysql_fetch_assoc($result); echo "<p>Welcome User : ".$_SESSION["pfno"]. "<p>Logged in: " .date("m/d/Y", $_SESSION["valid_time"]); ?> </body> </html> this -> <?php $_SESSION['pfno'] = "$username";?> was where the problem was all these while. Variable Issues...obviously. One more thing Bj, suppose I wanted to retrieve and display information concerning the current user from a table in the db how do I go about it? Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-891197 Share on other sites More sharing options...
tobimichigan Posted August 5, 2009 Author Share Posted August 5, 2009 Oh, I almost forgot, here's now the output: Members Area | Edit Profile | Reports | Logout Welcome USER : 2345(<-this is what I was targeting) Logged in: 08/05/2009. Thanks once again Bj. I'm waiting for your answer on my next question. Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-891221 Share on other sites More sharing options...
Bjom Posted August 5, 2009 Share Posted August 5, 2009 same as before with the pfno and such... $result = mysql_query("Select * From user_table where pfno='$username'",$link); add a var_dump($result); after that line and see what it gives you. If you need a different table...query it. Throw the value you want into a session variable....done Quote Link to comment https://forums.phpfreaks.com/topic/168832-solved-problem-with-displaying-username-on-1st-restricted-page/#findComment-891232 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.