LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Add additional checking (https://www.linuxquestions.org/questions/linux-newbie-8/add-additional-checking-331707/)

edhan 06-08-2005 08:25 PM

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 !

juanbobo 06-08-2005 09:24 PM

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);
       
?>


edhan 06-09-2005 08:15 AM

Hi

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

Thanks!

juanbobo 06-09-2005 09:58 AM

What else do you need?

edhan 06-09-2005 10:03 AM

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!

juanbobo 06-09-2005 11:45 PM

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.";
               
?>


edhan 06-10-2005 12:37 AM

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!

edhan 06-11-2005 10:37 AM

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");


juanbobo 06-11-2005 08:45 PM

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".

edhan 06-11-2005 10:02 PM

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!


All times are GMT -5. The time now is 10:55 PM.