top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

PHP: Is there a way to combine current active user in class with session variables for multiple use?

0 votes

I have a question about using a php user class and session variables. Let's say that I have managed to create a user class that finds a particular person from the database query.

As I move about the site from page to page it would be nice to be able to use the current user inside the user class without needing to re – look them up in the database multiple times

Q: so is there a way to combine the current active user in the class with session variables so that they can be used multiple times? If so, how would this work?

posted Aug 21, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

This really is not a class issue. When you call the class to determine the record ID of the user, you will save it in a variable. Probably created by calling the class to instantiate the variable.

What is important is understanding sessions, to track repeated page accesses. This is a good start:

Now for security reasons, DO NOT USE the record ID as the session variable. Save the session ID and record ID pair in either the database or the host file system.

answer Aug 21, 2014 by Seema Siddique
OK Thanks for the help. So forgetting about the class issue

Assuming that site will need to display the fields separately on different pages (just first name on some - full info on others etc.).....

Do you recommend setting session vars after the primary query for each of the user fields like:

$_SESSION['first'] = "joe";
$_SESSION['last'] = "smith";
$_SESSION['phone'] = "212 111 2222";

etc. ?

Or might I set a session user var like...

$_SESSION['thisuser'] = array('joe','smith','212 111 2222');
echo 'show last name- '.$_SESSION['thisuser'][1].'

is there a customary way to do this?
There is no "customary" way.
Similar Questions
0 votes

I want to use session to pass variables through pages using php.
Site structure is:
1. header.php
2. column.php
3. footer.php
4. index.php
Pages 1, 2 & 3 are included into the index.php.

In header.php page, there is a drop down, in which links(cities) are placed where users will select city.
Now, I want to do code to store selected values into a variable and pass to multiple pages.

Please help on this..

0 votes

I would like to make a timeout length to session variables, so that if a user didn't use the browser page for let's say 5 minutes - the session variables would expire and the user would need to login again.

Q: What's the best way to implement this functionality?

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.