2 different user session

hi there im stuck on a section where there are 2 different users like A and B both have different tables for data the problem is in first user ie “A” the logout login works fine like if he goes back to index page heil his MYPROFILE link where he can visit his profile page but for user B i added the same code but when the user goes to index he can see two profile links one of the user A and his B im using session code in that like this

  <!--USER SESSION-->
	<?php if(empty($_SESSION)):?>
	<li><a href="index.php">HOME</a></li>
	<?php else:?>
	<li><a href="A.php" >PROFILE</a></li>
	<?php endif;  ?>
	<!--END-->

<!--NGO SESSION-->
		<?php
		if(empty($_SESSION)):?>
		<li><a href="index.php">HOME</a></li>
		<?php else:?>
		<li><a href="B.php" >PROFILE</a></li>
		<?php endif;  ?>
<!--END-->

<li><a href="contact.php">CONTACT US </a></li>
<li><a href="#" >BLOG/UPDATES</a></li>

<?php if(empty($_SESSION)):?>
<li><a href="login.php" >LOGIN</a></li>
<?php else:?>
<li><a href="logout.php" >LOGOUT</a></li>
<?php endif;  ?>
<?php if(empty($_SESSION)):?>
<li><a href="register.php">REGISTER</a></li>
<?php endif;?>

what i want is if the user B goes to index page he will only see his profile page LINK not of user A please help

check who is logged in.

if($_SESSION['user'] == 'A') ... // show login page for A

see the index page has 2 home links the code says if empty show the home line else show the profile page of A or B.if the user B logs in and goes to index page heil see two profile links one of which is his if he clicks on profile ie of A the profile page will open but he wont see cuz its not his session i just want if user A logs in the user B profile shd be hidden vice versa

Surely the easiest way is to have the “profile” code (the code that runs when you click the ‘profile’ link) read the user ID from the session and display the appropriate information? If you think of User A and User B and code for their individual needs, what happens when you have 5000 users?

So, instead of linking to a.php or b.php, you link to profile.php and in the start of that code, read the user ID from the session data.

A and B i typed for easy understanding i hav profile.php n profile2.php i have added a seperate register for USER A and seperate for USER B,and i have a separate data table for user A(PROFILE) and B(profile)so its 10 or 5000 users it will get bifercated according to users registeration see my code

OK, so does that mean A and B are user types, something like admin and non-admin users? Do you have something in the session variables that will tell you which it is? That would seem to be the easiest way, or modify profile.php to contain the code for both user types, and run whichever is appropriate for the user type.

yess exactly, this session is for USER A

<?php
   session_start();
   

						  $link=mysqli_connect("localhost","root",'',"sysp");
						if($link===false)
						{
						 die("error cant connect".mysqli_connect_error());
						}
					   $user_check = $_SESSION['login_user'];  // what it is 
					   
					   $ses_sql = mysqli_query($link,"select email from user where email = '$user_check' ");
					   
					   $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
					   
					   $login_session = $row['email'];
					   
					   if(!isset($_SESSION['login_user']))
					   {
						header("location:login.php");
					   }
?>

this is for User B

<?php
   session_start();
	  if($_SERVER["REQUEST_METHOD"] == "POST") {
      $link=mysqli_connect("localhost","root",'',"sysp");
	if($link===false)
	{
	 die("error cant connect".mysqli_connect_error());
	}
   $user_check = $_SESSION['login_user'];
   
   $ses_sql = mysqli_query($link,"select email from ngo where email = '$user_check' ");
   
   $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
   
   $login_session = $row['email'];
   
   if(!isset($_SESSION['login_user'])){
      header("location:wrong.php");
   }
	  }
?>

So, all you need to do is have one profile.php page, at the start check in the session variable to see what type of user is logged in and run the appropriate code based on user type. When the user logs in, what do you do? Do you have two login pages depending on what type of user, or do you get their details, look through one table, and if not found look through the other table?

It seems in the above code you get the $_SESSION['login_user'] variable to use in the query, without checking to see if it exists. You check that later, but it would be more benefit to check earlier I think.

hey do you have team viewer uil understand better when seeing

No, sorry, nothing like that. Always easier to put enough detail on the forum so that others can come in with their opinions.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.