LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2005, 09:25 PM   #1
edhan
Member
 
Registered: Sep 2003
Location: Singapore
Distribution: Redhat 8.0
Posts: 93

Rep: Reputation: 15
Question Add additional checking


Hi

I am new to php & mysql database. I am doing a project on Login with username, password and verification with an additional field - Approval.

Instead of just allowing someone to login with the username and password, an additional verification field (Approval) is carried out to check if this account has been approved with data indicating as 'YES' from the database.

Would appreciate if someone can help to resolve or point to me where I can get an example of solving this problem.

Thanks !
 
Old 06-08-2005, 10:24 PM   #2
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Rep: Reputation: 30
This is an example, modified from something I used on a site. I used an "active" column in my database for which could be "approved" in your case...

Code:
<?php 
	session_register('loggedin');
	session_register('username');
	include('data.inc');
?>
<?php 


	$link = mysql_connect($host_mysql, $user_mysql, $password_mysql);

	mysql_query("use $database_mysql");
	
	$invalid = 0;
	
	if (!$_SESSION['loggedin']){
	
		$cookie_length = 14 * 24 * 60 * 60;
	
		if (isset($_POST['username']) and (isset($_POST['password'])) and (strlen($_POST['username']) > 0)){
	
			$result = mysql_query("select * from $users_mysql where username='$_POST[username]'");
			
			$info = mysql_fetch_array($result);
			
			if (($_POST['username'] == $info['username']) and (md5($_POST['password']) == $info['password']) and ($info['active'])){
			
				$_SESSION['loggedin'] = $info['user_type'];
				$_SESSION['username'] = $_POST['username'];	
				
				setcookie("username", md5($_POST['username']), time() + $cookie_length);
				setcookie("password", md5($_POST['password']), time() + $cookie_length);
			
			}
			
			else $invalid = 1;	
		}	
	
		elseif ((isset($_COOKIE['username']) and (isset($_COOKIE['password'])) and (strlen($_COOKIE['username']) > 0))){	

			$result = mysql_query("select * from $users_mysql where username='$_COOKIE[username]'");
		
			$info = mysql_fetch_array($result);
	
			if (($_COOKIE['username'] == $info['username']) and ($_COOKIE['password'] == $info['password']) and ($info['active'])){
			
				$_SESSION['loggedin'] = $info['user_type'];
				$_SESSION['username'] = $_COOKIE['username'];
				
			}
			
		}	
	
	}
	
	if (($_SESSION['loggedin'] == $user) or ($_SESSION['loggedin'] == $company)) echo "<p>Welcome <Strong> " . $_SESSION['username'] . "</Strong>!</p>";
	
	if ($_SESSION['loggedin'] == $admin) echo "Welcome <Strong>Administrator</Strong>! <a href='index.php?page=logout'>Logout</a>";
			
	if ($_SESSION['loggedin'] == $notloggedin) echo "<p>Welcome <Strong>Guest</Strong>!</p>";	
		
	
	mysql_close($link);
	
?>
 
Old 06-09-2005, 09:15 AM   #3
edhan
Member
 
Registered: Sep 2003
Location: Singapore
Distribution: Redhat 8.0
Posts: 93

Original Poster
Rep: Reputation: 15
Hi

Is it possible to give the entire login example. I am still new with this.

Thanks!
 
Old 06-09-2005, 10:58 AM   #4
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Rep: Reputation: 30
What else do you need?
 
Old 06-09-2005, 11:03 AM   #5
edhan
Member
 
Registered: Sep 2003
Location: Singapore
Distribution: Redhat 8.0
Posts: 93

Original Poster
Rep: Reputation: 15
Hi

I tried to use your example but it simply echo both the User and the Guest.

Therefore wondering the complete script for login.

Thanks!
 
Old 06-10-2005, 12:45 AM   #6
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Rep: Reputation: 30
Here is the login form which goes below what I previously sent. Sorry that is a bit messy.

Code:
<?php 
		
if ($_SESSION['loggedin'] == $notloggedin) 

echo "<form id='registration' name='registration' method='post' action='$_SERVER[PHP_SELF]' name='log' id='log'>";

echo "<p>Please enter your login informtion.<br><br>";

echo "Username: <INPUT type='text' size='12' maxlength='12' name='username' id='username'>";

echo "Password: <INPUT type='password' size='12' maxlength='12' name='password' id='password'>";

echo "<input type='submit' value='Log In' name='welcome'></form>"; 

if ($invalid == 1) echo "<p style='color:red;'>&nbsp;Login invalid.";
		
?>

Last edited by juanbobo; 06-10-2005 at 12:52 AM.
 
Old 06-10-2005, 01:37 AM   #7
edhan
Member
 
Registered: Sep 2003
Location: Singapore
Distribution: Redhat 8.0
Posts: 93

Original Poster
Rep: Reputation: 15
Hi juanbobo

Thank you for the code. I have tried combining both codes together but do not seem to get it working for the verification
as it prompt Login invalid.

If it is not too much to ask, can you show the complete working example?

Thanks!
 
Old 06-11-2005, 11:37 AM   #8
edhan
Member
 
Registered: Sep 2003
Location: Singapore
Distribution: Redhat 8.0
Posts: 93

Original Poster
Rep: Reputation: 15
Hi

I know the login for the database but can't seem to figure out how your code works with my table. Basically my table
consists of only UserID, Password and Approval (Yes or No). How do I input this with your code?

Thanks!

My login code is:

Code:
  include("config.php");
   $dbConnect = mysql_pconnect(null,$dbUserName ,$dbPassword);

  $INFO['sql_db'] = "admin";
  $INFO['sql_host'] = "localhost";

  mysql_select_db($INFO['sql_db']) or die("Could not select database");
 
Old 06-11-2005, 09:45 PM   #9
juanbobo
Member
 
Registered: Mar 2005
Location: Chicago
Distribution: Gentoo AMD64
Posts: 365

Rep: Reputation: 30
Here you can read about HTML forms, just create a form with three fields for username, password, and approval...

http://www.w3schools.com/html/default.asp

http://www.php.net is a great reference for PHP commands such as those related to MySQL.

Look up the command mysql_fetch_array(), you can use it to access data for your database.

You have null for the host, I would use "localhost".

Last edited by juanbobo; 06-11-2005 at 09:50 PM.
 
Old 06-11-2005, 11:02 PM   #10
edhan
Member
 
Registered: Sep 2003
Location: Singapore
Distribution: Redhat 8.0
Posts: 93

Original Poster
Rep: Reputation: 15
Hi

I need the php login with username and password but with a hidden checking as whether that user is approved or not that
denotes by Yes or No field. As I am just a beginner, I really need help to have the php code how I can do it.

Do you know how to write the code?

Thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Very easy method to add additional port for SSH? aulix Linux - Networking 6 07-17-2004 09:50 PM
How to add additional hard disc after installation osward Linux - Newbie 10 03-28-2004 07:01 PM
Add Additional Hard Drives rawdave Linux - Newbie 3 03-17-2004 10:47 AM
Best way to add additional window managers post setup ? Raptor Ramjet Slackware 3 12-27-2003 03:14 PM
RH8, would it be possible to add additional language support after installation? luoluotu Linux - Newbie 3 12-20-2002 06:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration