Welcome to Discuss Everything Forums...

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.


 

Tags for this Thread

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    webdesignkid
    webdesignkid's Avatar
    Guest

    PHP Question about session variables. How do I start a session? New to PHP

    and I have some ?'s before I start? I am trying to create a client login area for my clients to each see there information (received from a MySQL Database) when they login.

    I have created the login page in Dreamweaver CS3 and that works but now I think I need to start a session in order for it to say
    Welcome, Username and have that users information.

    Please help. Where would I begin the session in my code and is this even possible? What do I need to do to request a certain field from my database based on the username and password entered from the form.

    A Breakdown of what I am asking:
    - Clients login and are sent to the main php page. I accomplished this

    - Clients are greeted with Welcome, Client and there information
    * I need help with this.

    - How do I insert certain fields and records (only the ones associated with the client that logged in)

    Again, I am using Dreamweaver CS3

    You can also post some links to resources, that will answer some of these questions for me.

    THANKS!!!!!!! Help is appreciated.
    Would AddProperty & Add Value be replaced with something? My guess is yes but I am not sure what.

  2. #2
    DzSoundNirvana
    DzSoundNirvana's Avatar
    Guest
    <?
    /***************************
    login.class.php
    ***************************/
    class user{
    //To track the switch/errors through out
    var $login_error;

    //constructor
    function user($UserInput){
    $this->login_form();
    }//End function


    //Just a simple login form
    function login_form(){
    echo "<div align=\"center\"><form name=\"LoginForm\" action=\"$_SERVER[PHP_SELF]\" method=\"POST\"><table><tr><td><tr><td>User Name:</td><td><input type=\"text\" name=\"FLU\"></td><td>Password:</td><td><input type=\"password\" name=\"FLP\"></td></tr><tr><td colspan=\"2\"><input type=\"submit\" value=\"Submit\"> <input type=\"reset\" value=\"Reset\"></td></tr></table></div>";

    }//End Function

    function validate_user($UserInput){

    //my chosen user name and password pattern
    $this->user_name_pattern = ("^[a-zA-Z0-9]{5,15}$");
    $this->password_pattern = ("^[a-zA-Z0-9\!\@\#\$\%\^\&&#92;*\`\~\_]{5,15}$");
    //JavaScript History -1
    $this->go_back = <a href=javascript:history.go(-1)><font color=red size=-2>(Go Back)</font></a>;
    $this->success_login_redirect = "http://dzsoundnirvana.com/";

    switch($UserInput){
    case ($UserInput['FLU'] == "" || !ereg($this->user_name_pattern,$UserInput['FLU'])):
    $this->login_form();
    echo "<div align=\"center\"><font color=\"red\">Invalid user name. Try again or $this->go_back!</font></div>";
    $this->login_error == false;
    break;

    case ($UserInput['FLP'] == "" || !ereg($this->password_pattern,$UserInput['FLP'])):
    $this->login_form();
    echo "<div align=\"center\"><font color=\"red\">Invalid password. Try again or $this->go_back!</font></div>";
    $this->login_error == false;
    break;
    }
    if($this->login_error === false){
    //Or you can redirect to a "Forgot password/user name" page or leave it alone. This will kill the script. No output after though!
    exit;
    }
    else{
    //Now we go to the Database and validate the user
    $this->db();
    $this->query_string = "SELECT * FROM users WHERE user_name='$UserInput[FLU]' && password='" . md5($UserInput['password']) . "'";
    $this->query = mysql_query($this->query_string);
    //Error check the query
    if(!$this->query){
    echo "System error! Contact the system administrator!<br>or<br>$this->go_back";
    //use this for debugging (below), Delete the // at the beginning
    //echo mysql_error();
    }
    else{
    //Need to check if more than 1 user exists if so....throw HACKING error (not supported here)..another class
    $this->num_rows = mysql_num_rows($this->query);
    if($this->num_rows > 1){
    echo "Hacking warning";
    exit;
    }
    else{
    //Get the user information and set into the $_SESSION and then redirect to the directed page
    $this->user_information = mysql_fetch_assoc($this->query);
    //Put all user data into $_SESSION
    foreach($this->user_information as $key => $value){
    $_SESSION[$key] = $value;
    //Now we redirect to the page specified
    echo "<script type=\"text/javascript\">window.location=\"$this->success_login_redirect\"</script>";
    echo "If you are not redirected <a href=\"this->success_login_redirect\" target=\"_parent\">Click here to continue</a>";
    }
    }

    }//else

    }//if($this->login_error === false)/else{


    }//End function

    function db(){
    $this->db_link = mysql_connect("data_base_host","data_base_user","d ata_base_password]);
    //Select the DB
    $this->db_select = mysql_select_db("data_base_name");

    }


    }//End Class
    ?>

 

 

Quick Reply Quick Reply

Click here to log in


What color is our footer?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Session variables in PHP not being consistent.?
    By maddy in forum Discuss PHP
    Replies: 0
    Last Post: 06-23-2011, 12:51 PM
  2. PHP help please! Session variables?
    By Justin in forum Discuss PHP
    Replies: 0
    Last Post: 06-11-2011, 01:49 AM
  3. PHP session variables?
    By Marc in forum Discuss PHP
    Replies: 0
    Last Post: 12-03-2010, 04:39 AM
  4. How do I maintain session variables in php?
    By jamie m in forum Discuss PHP
    Replies: 0
    Last Post: 02-19-2010, 12:55 PM
  5. Using PHP Session Variables?
    By Codeman in forum Discuss PHP
    Replies: 1
    Last Post: 04-07-2009, 10:02 AM

Bookmarks

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •