954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Seeion handeling

Hi all,
I try to make login page in PHP.But I unable to get the loginID/UserName in login_successful page.I try to do it by using session.Please anyone tell me how I solve this problem by using session.

Shreyasi
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

hi shreya,

<?
ob_start();
include("../conn.php");
if($_SERVER['REQUEST_METHOD']=="POST" && isset($_POST['rlog']))
{
$res="select * from `date_profiles` where email='".mysql_real_escape_string($_POST['login'])."' and password='".mysql_real_escape_string($_POST['pass1'])."'";
$res1=mysql_query($res);
$res2=mysql_num_rows($res1);
if($res2==0)
{
echo "invalid user";
} else{
$res="select * from `date_profiles` where email='".$_POST['login']."' and password='".$_POST['pass1']."'";
$res1=mysql_query($res);
$row=mysql_fetch_assoc($res1);
$id=$row['id'];
session_unregister("user_id");
  session_register("user_id");
   $_SESSION['user_id']=$id;
  session_unregister("name");
  session_register("name");
   $_SESSION['name']=$row['fname'];
header("location:index.php");
}
}

?>

hope this will help u

praveen_dusari
Posting Whiz in Training
204 posts since Jun 2008
Reputation Points: 21
Solved Threads: 29
 

use this code in your application:

session_start();
//these folllowing lines are after insert query...
session_unregister('userid');
		   session_unregister('password');		   
		   
		   session_register('userid');
		   session_register('password'); 
		   		   
		   $_SESSION['userid']=$_POST['userid'];
		   $_SESSION['uid']=$_POST['password'];


And in your next page:

session_start();
echo $_SESSION['userid'];
echo $_SESSION['password'];

let me know if any error comes....

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

hi,
the above code i posted in inlogin page and in outher page like login succesful u can use sessions like this

<table  border="0" cellspacing="0" cellpadding="0">
          <? if(isset($_SESSION['user_id']) && isset($_SESSION['name'])) {?>
          <tr>
            <td width="113" class="us">Welcome :
              <?=$_SESSION['name'];?></td>
            <td width="19"><img src="../images/spacer.gif" width="12" height="1" /></td>
            <td width="10" bgcolor="#FF9999"><img src="../images/spacer.gif" width="1" height="1" /></td>
            <td width="12"><img src="../images/spacer.gif" width="12" height="1" /></td>
            <td width="96"><a href="signout.php" class="signup">LogOut</a></td>
          </tr>
          <? }else { ?>
          <tr>
            <td height="1" class="us">Welcome : <strong>Guest</strong></td>
            <td>&nbsp;</td>
            <td bgcolor="#FF9999"></td>
            <td>&nbsp;</td>
            <td><a href="#" class="signup">Sign Up </a></td>
          </tr>
          <? } ?>
        </table>

if user logged in then it will display welcome (username) otherwise it will display
welcome guest
i think its clear now any doubts let us know

praveen_dusari
Posting Whiz in Training
204 posts since Jun 2008
Reputation Points: 21
Solved Threads: 29
 

Thanks...It works in IE.But not in mizila...no error shown but after login not going to next page..

Shreyasi
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

Could you please tell me,
what is the structure of data base for this program???
What is rlog here??($_POST['rlog'])

Shreyasi
Newbie Poster
8 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 

I think $_POST['rlog'] is a submit button.

roh3x2n
Newbie Poster
8 posts since Oct 2006
Reputation Points: 10
Solved Threads: 1
 

hi shreyasi,
i wrote a script for login which has 2 fields username and password if user is already registered then he will simply login, these two fields are placed at right.php and included in every page and if he is not registered user he will register in registerpage,after completion he will be logged in. so, to avoid confusion fom which the user is logged in i took one hidden value rlog in one right.php,structure is pretty complex becoz i used same table for different modules in my project which may be very confusion for u(i think) based on ur requirement u create your
tables

praveen_dusari
Posting Whiz in Training
204 posts since Jun 2008
Reputation Points: 21
Solved Threads: 29
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You