Page 1 of 1

how to convert simple php script into a class for AMFPHP ?

Posted: Wed Dec 10, 2008 3:11 am
by joomoo79
Hey guys,

I'm starting with AMFPHP... I have this code that I wanna turn into a class that I can use directly into AMFPHP... But I'm not sure how to proceed. I played around but I get errors of course. So I'll appreciate any help that shows me what the result should look like, with a little explanation if possible... so I can do it on my own. ^_^

Code: Select all

 
<?php
//login.php
include "connect.php";
 
//This page gets called when a user attempts to login
 
//POST the information
$username = $_POST['username'];
$password = md5($_POST['password']);
$cookie = $_POST['cookie'];
 
//If the checkbox was checked set a cookie called "fd_mem_user" and set its value equal to the username
if($cookie != "")
{
    setcookie("fd_mem_user",$username, time() + 31536000,"/");
}
else
{
    //If its was previously set and then the user unchecks it, set the same cookie equal to nothing and the expiration time to one hour before the current time.
    setcookie("fd_mem_user","", time() - 3600,"/");
}
 
$query = mysql_query("SELECT * FROM $tableName WHERE username = '$username' AND password = '$password'") or die(mysql_error());
$num = mysql_num_rows($query);
if($num < 1)
{
    //no username/password combo was found
    echo "result=fail";
}
else
{
    //username/password combo found. Give the access. User info gets displayed
    $row = mysql_fetch_array($query);
    echo "result=success";
    echo "&username=$row[username]";
    echo "&email=$row[email]";
    echo "&firstname=$row[firstname]";
    echo "&lastname=$row[lastname]";
    echo "&address1=$row[address1]";
    echo "&address2=$row[address2]";
    echo "&city=$row[city]";
    echo "&state=$row[state]";
    echo "&zip=$row[zip]";
    echo "&phone=$row[phone]";
    echo "&date_added=$row[date_added]";
}
?>
 
THANK YOU GUYS!!!

Re: how to convert simple php script into a class for AMFPHP ?

Posted: Wed Dec 10, 2008 4:51 am
by joomoo79
Waiting for your help, I made some changes... I managed to get a working service but I have a problem with echo. (see the comment in the appended code)

Code: Select all

 
<?php
 class Login {
    
    function Login() {
        
        $this->methodTable = array(
 
            "doLogin" => array(
                "description" => "Login to database",
                "arguments"=> array("username", "password"),
                "access" => "remote"
            ),
            "safe_stripslashes" => array(
            "description" => "No description given.",
            "arguments" => array("buf"),
            "access" => "private"
    )
        );
        
        $link = mysql_connect("localhost", "sebastien", "fabrice");
        $db = mysql_select_db("test", $link);
 
        $username = $_POST['username'];
        $password = md5($_POST['password']);
        $cookie = $_POST['cookie'];
        
        if($cookie != "")
        {
            setcookie("fd_mem_user",$username, time() + 31536000,"/");
        }
        else
        {
            setcookie("fd_mem_user","", time() - 3600,"/");
        }
    }
    
    function doLogin($username, $password){
    
        $query = "SELECT * FROM users WHERE user_id = '$username' AND user_pwd = '$password'";
        $num = mysql_query($query);
        
        if($num < 1)
        {
            echo "result=fail";
        }
        else
        {
            $row = mysql_fetch_array($num);
/* 
I get the following results :
message = "faultCode:INVALID_AMF_MESSAGE faultString:'Invalid AMF message' faultDetail:'result=success&username=tester1'"
name = "Error"
rootCause = (null)
I can see it's finding the right username - tester1 - but I mess up the rest. lol
*/
            echo "result=success";
            echo "&username=$row[user_id]";
        }
        
    }
 }
?>