Page 1 of 1

checking one among two session?

Posted: Mon Oct 17, 2005 11:55 am
by rami
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Checking two session(any one)
i have student login which creates session

Code: Select all

session_start();      
$_SESSION['name'] = $row[1]; 
            $_SESSION['user_id'] = $row[0]; 
when sucessfully logged....
and admin login page which creates ...

Code: Select all

session_start();      
$_SESSION['susername'] = $row[1]; 
            $_SESSION['suser_id'] = $row[0];
on sucessful login....(both student and admin separate tables)

i have a page that displays details of student i want both admin and student ,able to view that page on sucessful login
i try to do these but none worked...in beginning of page

Code: Select all

1)if (!(isset($_SESSION['user_id'])) OR (!isset($_SESSION['suser_id'])))


2)if (!isset($_SESSION['user_id']) || !isset($_SESSION['suser_id']) ) 

3)if (!isset($_SESSION['user_id']) OR (!isset($_SESSION['suser_id'])))
currently i am using(which is working)

Code: Select all

if (!isset($_SESSION['user_id']))// i replaced this for test
{

	header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
	ob_end_clean(); // Delete the buffer.
	exit(); // Quit the script.
	
} else { .....
but this way only student is able to view that page

what is correct syntax or what should i do
any help....


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Oct 17, 2005 12:34 pm
by AGISB
I think your initial try is not working.

I suspect you got a database table including the usernames, passwords and which group the person belongs to.

So do it like this:


1. Let someone signin with their username and password. This can be done on the same page
2. Check if the credentials are ok and read the group table of that person
3. Simply do a if else on which group is read and display the appropriate site. You can then store the value for username and group in a session var and do a simple if else on the next pages as well.

Posted: Tue Oct 18, 2005 12:53 am
by rami
i think i had used php code when necessary
then what is that red marks for.....


any way i have working logic
what is not working is code bcoz i am new to php anddont know detail syntax
my question is
how is this checking session
(two session)
if either one exit then the page is viewable
if (!(isset($_SESSION['user_id'])) OR (!isset($_SESSION['suser_id'])))


2)if (!isset($_SESSION['user_id']) || !isset($_SESSION['suser_id']) )

3)if (!isset($_SESSION['user_id']) OR (!isset($_SESSION['suser_id'])))

(student is diff table with user_id ,pass ..stored..
admin is diff table with suser_id ,pass ..stored....

i am trying to use that if caluse in page that is viewable to both admin and student

please check tht login page code as well of first post
i think some braces is making is logically incorrect...
if i do this
if there is both session only then only code works
that OR is not working
so i feel it just logical error becoz of not knowing all syntax
so any body know how to do it
thanks for replies

Posted: Tue Oct 18, 2005 1:48 am
by mickd
just incase im going to ask:

do you have session_start(); called at the beginning of every page that uses sessions?

for example this page

Code: Select all

if (!isset($_SESSION['user_id']))// i replaced this for test 
{ 

    header ("Location:  http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php"); 
    ob_end_clean(); // Delete the buffer. 
    exit(); // Quit the script. 
     
} else { .....

Posted: Tue Oct 18, 2005 12:30 pm
by rami
i think people are not getting what i am trying to achieve

i have session_start() in each page...

if i check only one session it works very fine...

the problem starts when i try to check two session (if either of two exist then the users gets in to that page)
can i do this...

Code: Select all

if (!isset($_SESSION['user_id']) || !isset($_SESSION['suser_id']) )
but it is not working..........

whats the correct syntax for checking the two session....

any help