Discussion:
A Question About Using A Php User Class And Session Variables
dealTek
2014-08-21 16:39:51 UTC
Permalink
Hi all,

Newbie learning about php Classes…

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?

--
Thanks,
Dave - DealTek
***@gmail.com
[db-14]
Stephen
2014-08-21 16:50:44 UTC
Permalink
Post by dealTek
Hi all,
Newbie learning about php Classes…
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?
--
Thanks,
Dave - DealTek
[db-14]
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:

http://www.tizag.com/phpT/phpsessions.php

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.
--
Stephen
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
dealTek
2014-08-21 18:27:52 UTC
Permalink
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.
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].'<br>';

is there a customary way to do this?
http://www.tizag.com/phpT/phpsessions.php
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.
--
Stephen
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
Thanks,
Dave - DealTek
***@gmail.com
[db-14]
Tony Marston
2014-08-22 08:04:59 UTC
Permalink
Post by dealTek
Post by Stephen
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.
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
$_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].'<br>';
is there a customary way to do this?
There is no "customary" way. You do whatever works for you.
--
Tony Marston

http://www.tonymarston.net
http://www.radicore.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Loading...