hi...My friend of mine told to use this code

if($session->isAdmin()) the check if the user is logged in & has admin privileges

if($session->logged_in) to check if the user is logged in (simple user)

in login system.but it doesnt work at all..i want that if i login into the system,my name saved on database will appear on the right side of my page..
I used this

Hi,<?php ($session->username);

in my code..But it didn't work..

Recommended Answers

All 7 Replies

Hey.

How does the class for your $session variable look like?
Without knowing that, there is really no way for us to tell what your problem may be.

I do, however, suspect your friend meant the code to be used somewhat like this:

<?php
if($session->logged_in) 
{
    echo "Hi, {$session->username}";

    if($session->isAdmin()) 
    {
        // Do admin stuff
    }
}
else 
{
    echo "Welcome, guest!";
}
?>

But, like I say; this is pure speculation.

Hey.

How does the class for your $session variable look like?
Without knowing that, there is really no way for us to tell what your problem may be.

I do, however, suspect your friend meant the code to be used somewhat like this:

<?php
if($session->logged_in) 
{
    echo "Hi, {$session->username}";

    if($session->isAdmin()) 
    {
        // Do admin stuff
    }
}
else 
{
    echo "Welcome, guest!";
}
?>

But, like I say; this is pure speculation.

i try this code in my program..it works well but it only display the

echo "Welcome, guest!";

when i logged into the system.. what i want is when i logged into the system,the username i used saved in the database must display in the webpage..

Hey.

How does the class for your $session variable look like?
Without knowing that, there is really no way for us to tell what your problem may be.

I do, however, suspect your friend meant the code to be used somewhat like this:

<?php
if($session->logged_in) 
{
    echo "Hi, {$session->username}";

    if($session->isAdmin()) 
    {
        // Do admin stuff
    }
}
else 
{
    echo "Welcome, guest!";
}
?>

But, like I say; this is pure speculation.

after the voter enter their student no as well as their birthday,all information of that person must display in the webpage which are student no.,name,bday,course,year and department...i had my database-records for all voters.

Can you show us the class which you used to create the $session object?

Without seeing the class I can't really say anything of use. What I posted in my last post was my best guess. To do better I need more info on what that class looks like.

Can you show us the class which you used to create the $session object?

Without seeing the class I can't really say anything of use. What I posted in my last post was my best guess. To do better I need more info on what that class looks like.

class of my database?anyway,i do not have any idea in using the class that you were saying..because as i've said,my friend only gave it..hmm anyway,this is my database:

CREATE TABLE `students` (
  `id` tinyint(4) NOT NULL auto_increment,
  `studno` varchar(10) NOT NULL,
  `name` varchar(32) NOT NULL,
  `course` varchar(8) NOT NULL,
  `year` int(32) NOT NULL,
  `department` varchar(25) NOT NULL,
  `birthday` varchar(6) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=128 ;

but i only use to enter of the voter the studno and bday..

No, I mean the PHP class that defines how the object works.

Somewhere in your code the $session variable is created. That would read something like:

$session = new ClassName;

And at some other point in the code, the class ClassName (which is only an example name, not the real one) is defined. Something like:

class ClassName {
    // A bunch of other PHP code.
}

To be able to tell you anything useful, I need to see that PHP code.

Perhaps your friend - the one who gave you the code that isn't working - can help you figure out why it isn't working? Or at least help you find the code that would enable us to try to figure it out?

No, I mean the PHP class that defines how the object works.

Somewhere in your code the $session variable is created. That would read something like:

$session = new ClassName;

And at some other point in the code, the class ClassName (which is only an example name, not the real one) is defined. Something like:

class ClassName {
    // A bunch of other PHP code.
}

To be able to tell you anything useful, I need to see that PHP code.

Perhaps your friend - the one who gave you the code that isn't working - can help you figure out why it isn't working? Or at least help you find the code that would enable us to try to figure it out?

oh ok..hmmm anyway,my question is do you know how to display username based on the database.?i already posted my sql above..

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.