p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: Access Logger Script on page 474


Message #1 by "Eric Amidon" <eamidon@s...> on Tue, 22 Oct 2002 17:17:57
Hello...I'm having difficulties with this one. I'm trying to set up a 
password protected site that maintains the user's session state throughout 
the page. I decided to start with this one and am unable to get it to 
work. I believe my problems lies somewhere in this part of the code:

<?php
//auth_user.php
function auth_user($username, $userpassword) {
	global $default_user, $users_user;
	
	$link_id = db_connect($default_user);
	$query = "SELECT user_name from $users_user
				WHERE user_name = '$username'
				and userpassword = password
('userpassword')";
	$result = mysql_query($query);
	if(!mysql_num_rows($result)) return 0;
	else {
		$query_data = mysql_fetch_row($result);
		return $query_data[0];
	}
}

function login_form() {
	global $PHP_SELF;
?>

My database consists of a database called "users" with a table 
called "user". Inside that table is "user_name" and "password" where I 
have inserted one username and one password. I think I fudged up the code 
and I would appreciate any help with getting this running. Sorry if I made 
obvious mistakes. I'm really trying to get this in my head.

eric
Message #2 by "Philipp Feer" <svaziphil@s...> on Thu, 24 Oct 2002 18:25:17 +0800

-----Original Message-----
From: Philipp Feer [mailto:svaziphil@s...]
Sent: 24 Oktober 2002 18:24
To: 'beginning php'
Subject: RE: [beginning_php] Access Logger Script on page 474


I am not sure but it might be that you have to write:

$query =3D "SELECT user_name from $users_user
				WHERE user_name =3D '$username'
				and userpassword =3D
password('$userpassword')";

(userpassword with a $ ...)


phil

-----Original Message-----
From: Eric Amidon [mailto:eamidon@s...]
Sent: 22 Oktober 2002 17:18
To: beginning php
Subject: [beginning_php] Access Logger Script on page 474

Hello...I'm having difficulties with this one. I'm trying to set up a
password protected site that maintains the user's session state
throughout
the page. I decided to start with this one and am unable to get it to
work. I believe my problems lies somewhere in this part of the code:

<?php
//auth_user.php
function auth_user($username, $userpassword) {
	global $default_user, $users_user;
=09
	$link_id =3D db_connect($default_user);
	$query =3D "SELECT user_name from $users_user
				WHERE user_name =3D '$username'
				and userpassword =3D password
('userpassword')";
	$result =3D mysql_query($query);
	if(!mysql_num_rows($result)) return 0;
	else {
		$query_data =3D mysql_fetch_row($result);
		return $query_data[0];
	}
}

function login_form() {
	global $PHP_SELF;
?>

My database consists of a database called "users" with a table
called "user". Inside that table is "user_name" and "password" where I
have inserted one username and one password. I think I fudged up the
code
and I would appreciate any help with getting this running. Sorry if I
made
obvious mistakes. I'm really trying to get this in my head.

eric


  Return to Index