myphotomojo
Fri 29 December 2006, 01:18 pm GMT +0100
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
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