View Single Post
  #3 (permalink)  
Old October 28th, 2004, 07:32 PM
achalasia achalasia is offline
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The following is the PHP code at the start and the HTML for the form - I've removed everything else.

<?php
session_start();
header("Cache-control: private");

include 'global_variables.php';

if($_POST['process'])
{
    $muname = $_POST['username'];
    $mpass = $_POST['password'];

    $usname = addslashes($muname);
    $paword = addslashes($mpass);

    $connection = mysql_connect("$dbhost","$dbusername","$dbpasswd")
        or die ('Couldn\'t connect to server.');
    $db = mysql_select_db("$database_name", $connection)
        or die('Couldn\'t select database.');

    $query = "SELECT memberno, givenname FROM member WHERE UPPER(username) = UPPER('$usname') AND UPPER(password) = UPPER('$paword')";

    $result = mysql_query($query) or die ('Query failed');
    $num_result = mysql_num_rows($result);

    if($num_result==1)
    {
        $_SESSION = array();
        session_destroy();

        $row = mysql_fetch_array($result);
        $_SESSION['memberno'] = ($row['memberno']);
        $_SESSION['givenname'] = ($row['givenname']);
        $_SESSION['username'] = $muname;
        $_SESSION['password'] = $mpass;

        $errormsg = $errormsg."none";
    }
    else
    {
        $errormsg = "Please enter a valid username and password.";
    }
}

if($_POST['logout'])
{
    $_SESSION = array();
    session_destroy();

    $errormsg = $errormsg."logout";
}

if((!isset($_SESSION['username']))||(!isset($_SESSION['password'])))
{
    $muname = 'guest';
    $mpass = 'none';
    $mgname = 'Guest';

    $errormsg = $errormsg."guest";
}
else
{
    $muname = $_SESSION['username'];
    $mpass = $_SESSION['password'];
    $mgname = $_SESSION['givenname'];

    $errormsg = $errormsg."user";
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>Welcome To <?php echo htmlspecialchars($companyName) ?>!</title>

    <script language="JavaScript" type="text/javascript">
    <!--
    <!--

    <!--
    <!-- hide
    function validLogin(the_form)
    {
        if (the_form.username.value == "")
        {
            alert("You must enter a username.")
            the_form.username.focus()
            return false
        }
        if (the_form.password.value == "")
        {
            alert("You must enter a password.")
            the_form.password.focus()
            return false
        }
        return true
    }

    function subLogin()
    {
        if (validLogin(document.frm_login))
        {
            document.frm_login.submit()
        }
    }

    function subLogout()
    {
        document.frm_login.submit()
    }

    //-->
    </script>
</head>


<body style="background-color: rgb(0, 0, 0);">
<center>



    <form name="frm_login" method="post" action="index.php">
    <?php
        if(!$_SESSION['username'])
        {
    ?>
            <div style="float:left">
            <img src="images/spacer.gif" width="40" height="1" border="0">
            <span style="font-size: 9pt; color: rgb(204, 204, 204); font-family: arial; letter-spacing: 2px;"><b>U: </b></span>
            <input type="text" name="username" id="username" maxlength="10" size="20">
            <img src="images/spacer.gif" width="21" height="1" border="0">
            <span style="font-size: 9pt; color: rgb(204, 204, 204); font-family: arial; letter-spacing: 2px;"><b>P: </b></span>
            <input name="password" type="password" id="password" size="20" maxlength="10">
            <img src="images/spacer.gif" width="15" height="1" border="0">
            </div>
            <div style="float:right">
            <a href="javascript:subLogin()"><img src="images/login_button.jpg" alt="Login" name="btn_login" border="0"></a>
            </div>
            <input type="hidden" name="process" id="process" value="1">
    <?php
        }
        else
        {
    ?>
            <input type="hidden" name="logout" id="logout" value="1">
            <div style="float:left">
            <img src="images/spacer.gif" width="60" height="1" border="0">
            <span style="font-size: 9pt; color: rgb(204, 204, 204); font-family: arial; letter-spacing: 2px;">You are logged in.</span>
            </div>
            <div style="float:right">
            <a href="javascript:subLogout()"><img src="images/logout_button.jpg" alt="Logout" name="btn_logout" border="0"></a>
            </div>
    <?php
        }
    ?>
</form>

</center>
</body>
</html>


Reply With Quote