A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: flash login script

  1. #1
    Genisystems & Hiptop Design
    Join Date
    Dec 2007
    Location
    Bronx NY
    Posts
    5

    flash login script

    Hello all. I am having trouble getting this login script to work. does anybody have any suggestions. Please help me. Here is my actionscript and my php.

    Code:
    login.loginButton.onRelease = function() {
    	if (_root.login.userName.length>0 && _root.login.userPassword.length>0) {
    		myVars = new LoadVars();
    		myVarsReceive = new LoadVars();
    		myVars.username = escape(_root.login.userName.text);
    		myVars.pass = escape(_root.login.userPassword.text);
    		myVars.action = escape("Login");
    		myVars.sendAndLoad("http://www.hiptopdesign.com/login.php", myVarsReceive, 'POST');
    		myVarsReceive.onLoad = function() {
    			trace(this.error);
    			if (!this.error && this.user>0) {
    				_root.login.userName.text = "logged in"
    				_root.login.lstat.text = myVarsReceive;
    				trace(myVars);
    				trace(myVarsReceive);
    				slide(_root.login);
    			} else {
    				_root.login.userName.text = ""
    				_root.login.userPassword.text = ""
    				_root.login.lstat.text = "Error Logging in!";
    				trace(myVars);
    				trace(myVarsReceive);
    				shake(_root.login);
    			}
    			userName.selectable = true;
    			userPassword.selectable = true;
    			loginButton.enabled = true;
    		};
    		//userName.selectable = false;
    		//userPassword.selectable = false;
    		//loginButton.enabled = false;
    	}
    };

    PHP Code:
    <?php
    require_once('db.php');
    include(
    'functions.php');
        if(isset(
    $_POST['login']))
        {
            if(
    $_POST['username']!='' && $_POST['pass']!='')
            {
                
    //Use the input username and password and check against 'users' table
                
    $query mysql_query('SELECT ID, Username, Active FROM users WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['pass'])).'"');
                
                if(
    mysql_num_rows($query) == 1)
                {
                    
    $row mysql_fetch_assoc($query);
                    if(
    $row['Active'] == 1)
                    {
                        
    session_start();
                        
    $_SESSION['user_id'] = $row['ID'];
                        
    $_SESSION['logged_in'] = TRUE;
                        
    header("Location: members.php");

                    }
                    else {
                        
    $error 'Your membership was not activated. Please open the email that we sent and click on the activation link';
                    }
                }
                else {        
                    
    $error 'Login failed !';        
                }
            }
            else {
                
    $error 'Please user both your username and password to access your account';
            }
        }
    ?>

    <?php if(isset($error)){ echo $error;}?>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
        <input type="text" id="username" name="username" size="32" value="" />
        <input type="password" id="pass" name="pass" size="32" value="" />
            <input type="submit" name="Login" value="Login" />
    </form>

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    this looks fishy: _root.login.userName.length - looks like you are taking the length of an instance and not of the text input _root.login.userName.text.length

    Musicman

  3. #3
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    Rather than using:

    if (_root.login.userName.length>0 && _root.login.userPassword.length>0) {

    Try

    if (_root.login.userName.text != "" && _root.login.userPassword.text != "") {

    Otherwise what happens? Why is it not working?

  4. #4
    Genisystems & Hiptop Design
    Join Date
    Dec 2007
    Location
    Bronx NY
    Posts
    5

    still busted

    I tried both suggestions but its still not working. Do you think it has any thing to do with the headers line. or maybe im not passing the action login properly? What do you think?



    Quote Originally Posted by Musicman
    Hi,

    this looks fishy: _root.login.userName.length - looks like you are taking the length of an instance and not of the text input _root.login.userName.text.length

    Musicman

  5. #5
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    You need to echo error like this:

    <?php if(isset($error)){ echo "error=" . $error;}?>

    You also havent told us why it's not working? Are you getting an error, nothing happens, etc?

    In your PHP you can also remove the form and html markup. There is no need for that.

  6. #6
    Genisystems & Hiptop Design
    Join Date
    Dec 2007
    Location
    Bronx NY
    Posts
    5

    not getting an error

    I changed the php and took out the form.
    when i trace back out the loadvars after the send and load i get
    onLoad=%5Btype%20Function%5D
    also when i trace this.error and this.user i get undefined.

    this is my as code again. i dont think theres anything wrong with it.
    Code:
    trace("working");
    login.loginButton.onRelease = function() {
    	if (_root.login.userName.text != "" && _root.login.userPassword.text != "") {
    		myVars = new LoadVars();
    		myVarsReceive = new LoadVars();
    		myVars.username = escape(_root.login.userName.text);
    		trace(_root.login.userName.text);
    		myVars.pass = escape(_root.login.userPassword.text);
    		trace(_root.login.userPassword.text);
    		myVars.action = escape("login");
    		myVars.sendAndLoad("http://www.hiptopdesign.com/login.php", myVarsReceive, 'POST');
    		myVarsReceive.onLoad = function() {
    			trace(this.error);
    			trace(this.user);
    			if (!this.error && this.user>0) {
    				_root.login.userName.text = "logged in"
    				_root.login.lstat.text = myVarsReceive;
    				trace(myVars);
    				trace(myVarsReceive);
    				
    			} else {
    				_root.login.userName.text = ""
    				_root.login.userPassword.text = ""
    				_root.login.lstat.text = "Error Logging in!";
    				trace(myVars);
    				trace(myVarsReceive);
    				
    			}
    			userName.selectable = true;
    			userPassword.selectable = true;
    			loginButton.enabled = true;
    		};
    		//userName.selectable = false;
    		//userPassword.selectable = false;
    		//loginButton.enabled = false;
    	}
    };
    here is my php code after being updated
    PHP Code:
    <?php
    require_once('db.php');
    include(
    'functions.php');
        if(isset(
    $_POST['login']))
        {
            if(
    $_POST['username']!='' && $_POST['pass']!='')
            {
                
    //Use the input username and password and check against 'users' table
                
    $query mysql_query('SELECT ID, Username, Active FROM users WHERE Username = "'.mysql_real_escape_string($_POST['username']).'" AND Password = "'.mysql_real_escape_string(md5($_POST['pass'])).'"');
                
                if(
    mysql_num_rows($query) == 1)
                {
                    
    $row mysql_fetch_assoc($query);
                    if(
    $row['Active'] == 1)
                    {
                        
    session_start();
                        
    $_SESSION['user_id'] = $row['ID'];
                        
    $_SESSION['logged_in'] = TRUE;
                        
    header("Location: members.php");

                    }
                    else {
                        
    $error 'Your membership was not activated. Please open the email that we sent and click on the activation link';
                    }
                }
                else {        
                    
    $error 'Login failed !';        
                }
            }
            else {
                
    $error 'Please user both your username and password to access your account';
            }
        }
    ?>
    <?php 
    if(isset($error)){ echo "error=" $error;}?>
    Thanks alot. Im sitting by the computer waiting for your coveted response.

    Quote Originally Posted by sstalder
    You need to echo error like this:

    <?php if(isset($error)){ echo "error=" . $error;}?>

    You also havent told us why it's not working? Are you getting an error, nothing happens, etc?

    In your PHP you can also remove the form and html markup. There is no need for that.

  7. #7
    AS3 Mod
    Join Date
    Sep 2007
    Location
    O-H-I-O
    Posts
    2,385
    At the very top of your PHP page put:

    echo "error=if this returns then your login doesnt execute";

    Then tell me it returns that in flash

  8. #8
    Genisystems & Hiptop Design
    Join Date
    Dec 2007
    Location
    Bronx NY
    Posts
    5

    Its working

    Hello,
    I got it to work i had to change the word login in the fourth like to action in the php. but the myVarsRecieve still returns nonsense. Thanks for the help.



    Quote Originally Posted by sstalder
    At the very top of your PHP page put:

    echo "error=if this returns then your login doesnt execute";

    Then tell me it returns that in flash

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center