View Single Post
  #2 (permalink)  
Old December 4th, 2003, 12:10 PM
richard.york's Avatar
richard.york richard.york is offline
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Code:
<?php

function welcome()
{
    $connection = sql_connect();
    db_connect();

    global $table_name, $user_name, $user_password, $agent_name;

    if (empty($user_name))
    {
        echo "<span style='color: red; font-size: 10pt;'>Please enter your User Name</span><br />";
        login();
        exit();
    }

    else if (chk_user_name($user_name))
    {
        echo "<span style='color: red; font-size: 10pt;'>Your user name was not recognized! Please re-enter it!</span><br />";
        login();
        exit();
    }

    else if (empty($user_password))
    {
        echo "<span style='color: red; font-size: 10pt;'>Please enter your password!</span><br />";
        login();
        exit();
    }

    else if (in_use($user_password))
    {
        echo "<span style='color: red; font-size: 10pt;'>Your password is incorrect! Please re-enter it!</span><br />";
        login();
        exit();
    }

    else
    {
        global $table_name;

        $query                 = "SELECT * FROM $table_name WHERE user_name = '$user_name'";
        $result                = mysql_query($query);
        $query_data            = mysql_fetch_array($result);
        extract($query_data);

        $_SESSION["logged_in"] = mysql_num_rows($result);

        if ($_SESSION["logged_in"] == 1 && !isset($_SESSION["login_count"]))
        {
            $login_no++;

            $query2                  = "UPDATE $table_name SET login_no=$login_no WHERE user_name = '$user_name'";
            $result                  = mysql_query($query2);

            $_SESSION["login_count"] = true;
        }

        if ($_SESSION["logged_in"] == 1)

            echo "<span style='color: red; font-size: 10pt;'>Logged in as $agent_name of $co_name, you have logged in $login_no times</span><br />";
    }

}

?>
Well it isn't too difficult to add sessions into the mix here. For sessions to work you must make a call to session_start() at the very beginning of whatever page needs to use session data. No whitespace, no output, no anything before the opening <?php delimiter. And you also need to pass the session id.. the server will pass that id via cookies by default or you can pass the session id via url embedded arguments, which IMO is best because then you aren't relying on the user having cookies enabled.

See this thread:
http://p2p.wrox.com/topic.asp?TOPIC_ID=7205

And it would be best to avoid using deprecated HTML tags, like and <br> here is a thread that discusses why:
http://p2p.wrox.com/topic.asp?TOPIC_ID=4028

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote