Topic: get_user_info and non protected pages (Read 2183 times)
What a dork
Posts: 15
106 credits Members referred : 0
« on: Dec 29, 2006, 01:18:47 pm »
Hi Olaf,
I ran into a small problem when trying to use the get_user_info() function on a page that's not protected. Since this function is only valid on pages which are protected (i.e. access_page() called prior to get_user_info()), if you want to get the user info for non protected pages, it returns nothing.
Therefore, in your class I added a method called get_nonprotected_user_info() which is very similar to the get_user_info(). You can see it below:
function get_nonprotected_user_info() { if (isset($_SESSION['user']) && isset($_SESSION['pw'])) { $this->user = $_SESSION['user']; $this->user_pw = $_SESSION['pw']; } //$sql_info = sprintf("SELECT real_name, extra_info, email, id FROM %s WHERE login = '%s' AND pw = '%s'", $this->table_name, $this->user, $this->user_pw); $sql_info = sprintf("SELECT real_name, extra_info, email, id FROM %s WHERE %s = '%s' AND pw = '%s'", $this->table_name, $this->logtyp, $this->user, $this->user_pw); $res_info = mysql_query($sql_info); $this->id = mysql_result($res_info, 0, "id"); $this->user_full_name = mysql_result($res_info, 0, "real_name"); $this->user_info = mysql_result($res_info, 0, "extra_info"); $this->user_email = mysql_result($res_info, 0, "email"); }
Basically I just added a check to see if the user is valid. This way I can call get_nonprocted_user_info() on any page that doesn't need to be protected. Works good, but wanted to hear your comments as I might be using the class wrong.
Thanks for a great class.
Eric
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Dec 29, 2006, 01:27:13 pm »
the latest version has this function already, now you need only to create an object and both variables are created
What a dork
Posts: 15
106 credits Members referred : 0
« Reply #2 on: Dec 29, 2006, 01:40:13 pm »
hmmm, I thought I was using the lastest version. In the header for the access_user_class.php it says v.1.94. Is there something later? If so, where do I get it?
Thanks for the quick response.
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #3 on: Dec 29, 2006, 01:49:40 pm »
oeps...
it looks like I need to release this version first
What a dork
Posts: 15
106 credits Members referred : 0
« Reply #4 on: Dec 29, 2006, 01:51:58 pm »
Ok, you had me going there for second . Anyway, great class by the way. I have a couple of other questions that I will be posting in new threads shortly.
Just another rainy day
Posts: 1
6 credits Members referred : 0
« Reply #5 on: Jan 07, 2007, 01:45:46 pm »
Hi Olaf any chance you can post only the code that takes care of this feature?
BTW the sample Eric submitted does not deal with the situation when there is no user logged in. The SQL will return 0 rows.
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
Hi Olaf any chance you can post only the code that takes care of this feature?
BTW the sample Eric submitted does not deal with the situation when there is no user logged in. The SQL will return 0 rows.
I know I need to hurry Will try it soon...
What a dork
Posts: 15
106 credits Members referred : 0
« Reply #7 on: Jan 08, 2007, 05:30:05 am »
kweiss,
I'm not sure I understand what your talking about with regards to not getting the user info if a user is not logged in. How do you propose to do that? If a user is not logged in, how does one go about determining who the user is and then doing the appropriate db lookup.
Would be interested in hearing your thoughts because it could be really helpful to be able to do this.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=5410