Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 3 of 3

Thread: php member login Please help

  1. #1

    Fla Script php member login Please help

    Hi Im trying to make a members login for my site but im having trouble getting any signal that the user has got in success fully. Here is my actionscript and php. My host is netfirms.
    Code:
    login.loginButton.onRelease = function() {
        if (login.userName.length>0 && login.userPassword.length>0) {
            myVars = new LoadVars();
            myVars.username = escape(login.userName.text);
            myVars.pass = escape(login.userPassword.text);
            myVars.action = "login";
            myVars.sendAndLoad("http://www.hiptopdesign.com/login.php", myVars, 'POST');
            myVars.onLoad = function() {
                if (!this.error && this.user>0) {
                    //_root.gotoAndStop('registered');
                    login.userName.text = "logged in";
                    _root.login.lstat.text = myVars;
                    trace(myVars);
                } else {
                    //_root.gotoAndStop('no_registered');
                    login.userName.text = "not logged in";
                    _root.login.lstat.text = myVars;
                    trace(myVars);
                }
                userName.selectable = true;
                userPassword.selectable = true;
                loginButton.enabled = true;
            };
            //userName.selectable = false;
            //userPassword.selectable = false;
            //loginButton.enabled = false;
        }
    };
    here is the php
    PHP Code:
    <?php
    require_once('db.php');
    include(
    'functions.php');
        if(isset(
    $_GET['Login']))
        {
            if(
    $_GET['username']!='' && $_GET['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($_GET['username']).'" AND Password = "'.mysql_real_escape_string(md5($_GET['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;
                                            echo 
    $_POST['username'];
                                            print 
    $_POST['username'];
                        
    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>
    please any thoughts would be appreciated

  2. #2
    1,839
    posts
    Registered User
    what does your onload trace?

    but anyway

    myLV.onLoad = function(){
    trace(this.error)
    }

    then in php change it to
    $error = 'error=errorwhatevertext&';

  3. #3

    traces undefined

    when i trace this.error i get undefined,
    and when i trace the loadVars after it has been sendandloaded i get a random string of nonsense
    myVars = action=Login&pass=diablo&username=josephnwachukwu
    myVarsReceive = %0D%0A%3Cform%20action=%22%2Flogin%2Ephp%22%20meth od%3D%22post%22%3E%0D%0A%09%3Cinput%20type%3D%22te xt%22%20id%3D%22username%22%20name%3D%22username%2 2%20size%3D%2232%22%20value%3D%22%22%20%2F%3E%0D%0 A%09%3Cinput%20type%3D%22password%22%20id%3D%22pas s%22%20name%3D%22pass%22%20size%3D%2232%22%20value %3D%22%22%20%2F%3E%0D%0A%20%20%20%20%20%20%20%20%3 Cinput%20type%3D%22submit%22%20name%3D%22Login%22% 20value%3D%22Login%22%20%2F%3E%0D%0A%3C%2Fform%3E& onLoad=%5Btype%20Function%5D

    i updated my code so it looks like this
    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);
                } 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;
        }
    };
    i updated th php a little also
    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>

Thread Information

Users Browsing this Thread

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

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012