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.

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

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....

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

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

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

I think $_POST is a submit button.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.